view: conditional includes

49 views
Skip to first unread message

v.

unread,
Sep 11, 2018, 7:15:31 AM9/11/18
to Fat-Free Framework
Is there an easy way to include an html snippet in a view, using a variable name?
Eg.: my controller sets a variable q['type']='select' or q['type']='radio' (or any other type of html input).

Can you call the @q['type'] variable in the include statement of the view?
This returns a 500 error:
<include href="{{@q['type']}}.htm" />

I am now using nested check statements in the view and that does the trick but if above code would work I can condense 40 lines to 1 line

richgoldmd

unread,
Sep 11, 2018, 7:44:13 AM9/11/18
to f3-fra...@googlegroups.com
This should work but you can also specify 

<include href="{{ @q.type }}.htm" />



I use this sort of construct all the time though in my case the variable is fully formed:
<include href="{{ @q.template }}" />
or similar.


Should work. Does the template file you are referencing exist in your view path?

Also for your conditionals you can use the if="" attribute instead of checks for your includes:
<include href="mytemplate.html" if="{{ some condition }}" />

Message has been deleted

ikkez

unread,
Sep 11, 2018, 10:20:51 AM9/11/18
to Fat-Free Framework
Try this one instead:

<include href="{{@q['type'].'.htm'}}" />

I think it's the way how the token to attribute substitution works, that's blocking the first approach here, but concatenating it within the token should work just fine.

v.

unread,
Sep 11, 2018, 10:31:58 AM9/11/18
to Fat-Free Framework
thanks ikkez, this did the trick.
Reply all
Reply to author
Forward
0 new messages