Issue 87 in ctemplate: Add ability to set variables in template

23 views
Skip to first unread message

ctem...@googlecode.com

unread,
Feb 17, 2012, 2:14:18 PM2/17/12
to google-c...@googlegroups.com
Status: New
Owner: ----
Labels: Type-Defect Priority-Medium

New issue 87 by j...@johnmckinzie.com: Add ability to set variables in
template
http://code.google.com/p/ctemplate/issues/detail?id=87

It would be nice to be able to set variable for a template in the template.
The use case would be for a set of web pages that use a common
header/footer. I would like to be able to set the scripts need for the
individual page in the template, and have those accessible to the included
header template.

// foo.tpl

{{! SCRIPTS[] = "main.js" }}
{{! SCRIPTS[] = "foo.js" }}

{{>HEADER}}

<p>Foo template</p>

{{>FOOTER}}

The header template could then use the SCRIPTS variable in a section. It
just doesn't feel right setting the necessary scripts in my C++ code.

ctem...@googlecode.com

unread,
Feb 19, 2012, 1:37:37 PM2/19/12
to google-c...@googlegroups.com

Comment #1 on issue 87 by jim.morr...@gmail.com: Add ability to set

The style of ctemplate is to do this stuff in your code. So your template
would be
outline.tpl:
header stuff
{{>BODY}}
footer stuff

Your C++ would be:
FillCommonDictionary(dict);
... add my scripts to dict ..
TemplateDictionary body = dict->AddIncludeSection(ko_BODY);

ctem...@googlecode.com

unread,
Feb 19, 2012, 1:49:39 PM2/19/12
to google-c...@googlegroups.com

Comment #2 on issue 87 by j...@johnmckinzie.com: Add ability to set

I know it's possible. My point is for things such as adding script tags,
those really should belong in the view/template and not the C++ code. The
C++ code should know nothing about what CSS/JS files are needed in the HTML
template. From an MVC perspective, the controller should only be providing
data, not determining what additional tools the view needs to interact with
the user. Below is a link that shows how scripts can be set in the view
using CakePHP.

http://book.cakephp.org/1.3/view/1589/script (2nd paragraph)

ctem...@googlecode.com

unread,
Feb 23, 2012, 11:20:49 AM2/23/12
to google-c...@googlegroups.com

Comment #3 on issue 87 by olafv...@gmail.com: Add ability to set

Why don't you put the script tags in foo.tpl itself? Is there a need to put
them in header?

ctem...@googlecode.com

unread,
Mar 3, 2012, 5:02:49 PM3/3/12
to google-c...@googlegroups.com

Comment #4 on issue 87 by j...@johnmckinzie.com: Add ability to set

You can do this for scripts, however for CSS, the standard (HTML4/XHTML)
says the <style> tag may only be in the head element. This is also true in
HTML5 if you do not use the "scoped" attribute.

ctem...@googlecode.com

unread,
Mar 3, 2012, 7:55:31 PM3/3/12
to google-c...@googlegroups.com

Comment #5 on issue 87 by olafv...@gmail.com: Add ability to set

Isn't the recommendation for CSS (and JS) to have a single (minimized) file
anyway?

ctem...@googlecode.com

unread,
Mar 14, 2012, 1:11:27 PM3/14/12
to google-c...@googlegroups.com
Updates:
Status: WontFix

Comment #6 on issue 87 by olafv...@gmail.com: Add ability to set

(No comment was entered for this change.)

ctem...@googlecode.com

unread,
Mar 14, 2012, 1:15:30 PM3/14/12
to google-c...@googlegroups.com

Comment #7 on issue 87 by j...@johnmckinzie.com: Add ability to set

You would probably minify JS and CSS that's common to all pages, but I
think in most cases you would still be page/module specific JS/CSS separate.

ctem...@googlecode.com

unread,
Mar 14, 2012, 7:34:53 PM3/14/12
to google-c...@googlegroups.com

Comment #8 on issue 87 by olafv...@gmail.com: Add ability to set

Why would you do that?

Reply all
Reply to author
Forward
0 new messages