On Sat, Jun 28, 2014 at 12:52 AM, NSC <[email protected]>
wrote:

> I've always been slightly confused about how $var definitions work in a
> template, in regards to a base template. So, let me ask:
>
> In my 'sub' template (not base), I have something like this (straight from
> an example I found a year ago and lost):
>
> $var jsfiles: foo.js bar.js
>
> Then in the 'base' template I have this:
>
> $if content.jsfiles:
>     $for f in content.jsfiles.split():
>         <script src="$f"></script>
>
> Problem is, this approach *requires* each subtemplate to have $var
> jsfiles: even if I have no scripts to load for that page.
>
> Reading the code, I can't find a way to 'test' for the existence of a
> variable.  The page simply always throws a nasty error if the subpage
> doesn't define $var jsfiles:
>
> Anyone come up with a workaround for this?
>

You could do this:

$if content.get('jsfiles'):
    $for f in content.jsfiles.split():
        <script src="$f"></script>

Anand

-- 
You received this message because you are subscribed to the Google Groups 
"web.py" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/webpy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to