jjrjr1
Posts: 942
|
| Posted: 06/28/2008, 3:26 PM |
|
Hi
Has anyone tried to put a template value inside a javascript tag?
ie:<script..> var={SOMEFIELDFROMPHP};</script>
where SOMEFIELDFROMPHP is a control on a ccs form.
What I would like to do is have the google api key pulled from a mysql database.
fo I could have the code
<script .... src="http://googledomain/map?... key={keyfromdatabase}></script>
I cannot seem to get the template to fill with the value as inside just HTML.
Thanks
_________________
John Real - More CodeCharge Studio Support at - http://CCSElite.com |
 |
 |
mentecky
Posts: 321
|
| Posted: 06/28/2008, 5:30 PM |
|
Hey John,
I use a technique similar to what you want to set the titles on every page in the site based on a DB value. Since TITLE is outside of the viewable page I think this should work for your application as well. If not at least someone else might get some use out of it :)
I have to do a bit of explaining because my sample code will look screwed up without it.
First, I have a table where I store all my configuration information called system, defined as:
CREATE TABLE `system` (
`system_id` int(10) NOT NULL AUTO_INCREMENT,
`key_name` varchar(50) COLLATE latin1_general_ci DEFAULT NULL,
`value` varchar(255) COLLATE latin1_general_ci DEFAULT NULL,
PRIMARY KEY (`system_id`),
UNIQUE KEY `key` (`key_name`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci ROW_FORMAT=DYNAMIC;
It's a super simple table, but I use it for anything on the site that may need to change. key_name is the name of the parameter and value is the current value. I store things like Site Name, hit counters, SMTP info, AdSence keys and whatever I need in there.
I then have a function GetSystemParam, that retrieves these values. It is as follows:
// Retrieves a system parameter
function GetSystemParam($param, $default="")
{
$retval = $default;
$db = new clsDBMain();
$tmpval = CCDLookUp("value", "system", "key_name=".$db->ToSQL($param, ccsText), $db);
if (strlen($tmpval) > 0)
{
$retval = $tmpval;
}
return $retval;
}
OK, I know that was probably too much info but it was needed to explain these 2 lines of code. Put something like this in your page's Before Show event:
global $Tpl;
$Tpl->setvar("site_title", GetSystemParam("site_title", "Default Site Title"));
in my HTML in the <HEAD> block I have:
<title>{site_title} - Users List</title>
I know it's not a direct answer to your question, but I don't see why that won't work in your situation.
Good Luck,
Rick
_________________
http://www.ccselite.com |
 |
 |
datadoit
|
| Posted: 06/29/2008, 7:06 AM |
|
Read up on and learn all about that template variable ($Tpl). It'll
bring enormous power and flexibility to your applications, as Rick has
shown.
If your javascript code is based on an event (ie: onClick), then you can
also send the value of any CCS control by enclosing it in brackets:
onClick='YourJavascriptFunction({YourControl});'
YourJavascriptFunction(YourControl)
{
var TheValueYouWant = YourControl;
}
Separate note: Rick's example shows the VERY BEST way to search engine
optimize your application! CCS makes it super easy to do this by
dynamically changing page titles. Rick, if you haven't already, to be
safe and to optimize even more set up a sitemap page that matches your
page titles. As you change the page titles on each load, also write to
a database these values for the sitemap page.
|
|
|
 |
jjrjr1
Posts: 942
|
| Posted: 06/29/2008, 7:52 AM |
|
Thanks Guys.
This looks like exactly what I needed.
Take Care.
_________________
John Real - More CodeCharge Studio Support at - http://CCSElite.com |
 |
 |
mentecky
Posts: 321
|
| Posted: 06/29/2008, 10:47 AM |
|
John,
No Problem! Glad we could help.
datadoit,
Not to turn this into a SEO thread but...
I took your suggestions, kinda. On my site at http://www.meetwny.com I added code to make every page in the Forums, Gallery and Chat unique by adding their subject to the Title. Is this what you meant? I'm no SEO kinda guy. 
Also, I use standard links for all my menus. No JavaScript or CSS. Is it still necessary to do a site map?
Rick
_________________
http://www.ccselite.com |
 |
 |
datadoit
|
| Posted: 06/29/2008, 5:41 PM |
|
Yes. The spiders like 'fresh' content. They also like the title tag,
even more so than meta content and description. Changing the title
often is a good SEO thing, and CCS makes this task enormously easy.
They also like a sitemap page, a nice clean menu structure, and of
course fresh new page content. The more of the above options you do,
the better. Not only could you dynamically alter the title on every
page load, you could also dynamically update things like alt tags on
images/links to make the page seem 'fresh'. Just don't get too crazy
out of control with the alt tags in lieu of getting blacklisted.
|
|
|
 |
mentecky
Posts: 321
|
| Posted: 06/30/2008, 9:32 AM |
|
datadoit,
Thanks for the suggestions. Maybe, in your free time that I know all us developers have an a lot of, you could post a SEO tip thread. Feel free to use my post as part of your example if you'd like. I'd be interested in hearing more of your suggestions and I know I saw a plea for SEO help in the General board.
Rick
_________________
http://www.ccselite.com |
 |
 |
jjrjr1
Posts: 942
|
| Posted: 07/01/2008, 4:07 PM |
|
That sounds like a great Idea. Sign me up for that to.
By the way guys. Your tips worked great.
Thanks
_________________
John Real - More CodeCharge Studio Support at - http://CCSElite.com |
 |
 |
maxhugen
Posts: 272
|
| Posted: 08/22/2008, 2:52 AM |
|
Cool! 
I've always used a 'system' type table in my other apps like Mentecky; now I can see how to use it in CCS - and thanks to datadoit, I'm checking out the $Tpl a bit more closely too!
Good stuff!
_________________
Max
www.gardenloco.com | www.eipdna.com | www.chrisarminson.com |
 |
 |
maxhugen
Posts: 272
|
| Posted: 08/22/2008, 11:52 PM |
|
I've followed Rick's example closely to set the title (apart from a slight change to the lookup and system table) - but something is amiss.
In the Page_BeforeShow event I have:
global $Tpl;
$retval = gl_GetSystemParam("WebApp", "AppName", "Gardens");
echo $retval;
$Tpl->setvar("site_title", $retval);
The echo is returning the value AOK, but the Title isn't being set for some reason. I added a Label, and set the Control Source Type to 'Code Expression'. The html is:
<title>{site_title} - Welcome</title>
I can't spot what I've done wrong... anyone see the problem please?
_________________
Max
www.gardenloco.com | www.eipdna.com | www.chrisarminson.com |
 |
 |
wkempees
Posts: 1679
|
| Posted: 08/23/2008, 3:22 PM |
|
Max,
I assume you tested without the echo statement.
Then, In the HTML view, remove your label, rightclick it and choose Delete.
Save, Close, Reopen page in HTM View.
Place your mouse cursor where you want the title to appear later and just type
{SiteTitle}
Save, switch to Code view
Page Before Show:
global $Tpl;
$retval = gl_GetSystemParam("WebApp", "AppName", "Gardens");
$Tpl->SetVar("SiteTitle", $retval);
Should work after a full publish of that page.
The SetVar (CamelCaps) does not make a difference.
The SiteTitle does not either, was just done to force you to change it.
The plain typing of the {SiteTitle} in stead of placing a label from Form Toolbox does,
it forces the creation of a label in the code and that overrules your $Tpl assignment after the BeforeShow.
Hope you catch my writing.
Walter
_________________
Origin: NL, T:GMT+1 (Forumtime +9)
CCS3/4.01.006 PhP, MySQL .Net/InMotion(Vista/XP, XAMPP)
if you liked this info PAYPAL me: http://donate.consultair.eu
|
 |
 |
wkempees
Posts: 1679
|
| Posted: 08/23/2008, 3:25 PM |
|
Also, if you use any CCT (CodeChargeTools) product, there is a "CCT-Convert to JS String" action available in your Events actionlist.
It is a free action and it does some replacement of special characters.
Walter
_________________
Origin: NL, T:GMT+1 (Forumtime +9)
CCS3/4.01.006 PhP, MySQL .Net/InMotion(Vista/XP, XAMPP)
if you liked this info PAYPAL me: http://donate.consultair.eu
|
 |
 |
maxhugen
Posts: 272
|
| Posted: 08/24/2008, 5:46 PM |
|
Spot on as usual, Walter!
Just typing in {SiteTitle} instead of adding it as a Label did the trick.
Many thanks!
_________________
Max
www.gardenloco.com | www.eipdna.com | www.chrisarminson.com |
 |
 |
|