• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Template inclusion

Mythotical

Well-known member
#1
Here is the issue, I have a table setup with a row of temp_template each value is:
HTML:
<xen:include template="temp_name" />
The problem is that when I pull it in my foreach it won't display anything.
This is how I display it:
HTML:
{xen:raw $template.temp_name}
So any reason why it won't display the pull info or what I may be doing wrong?

Thanks
 

Lawrence

Well-known member
#2
This should work (if it is what you are trying to do):

<xen:foreach loop="$templates AS $tamplate">
<xen:include template="{$template}" />
</xen:foreach>
 

Mythotical

Well-known member
#4
Gave it a go, this is the error I get using that:
Code:
[LIST=1][*][I]htmlspecialchars() expects parameter 1 to be string, array given[/I] in C:\Program Files (x86)\Zend\Apache2\htdocs\xenforo\library\XenForo\Template\Abstract.php(208) : eval()'d code, line 17:
16: <div class="heading">' . htmlspecialchars($xpleft['temp_title']) . '</div>
17: <div class="secondaryContent middlem">' . htmlspecialchars($xpleft) . '</div>
18: ';
[*][I]htmlspecialchars() expects parameter 1 to be string, array given[/I] in C:\Program Files (x86)\Zend\Apache2\htdocs\xenforo\library\XenForo\Template\Abstract.php(208) : eval()'d code, line 17:
16: <div class="heading">' . htmlspecialchars($xpleft['temp_title']) . '</div>
17: <div class="secondaryContent middlem">' . htmlspecialchars($xpleft) . '</div>
18: ';
[/LIST]
 

Mythotical

Well-known member
#7
Ok trying your method the right way I should have done it, forgot to use the <xen:include> but here is the error when I did it right:
Code:
[SIZE=5][B]The following error occurred:[/B][/SIZE]

The following templates contained errors and were not saved:   xportal_left_column: 1)	Line 3: Invalid template include specified. A literal template name must be specified.[code]
 

Lawrence

Well-known member
#8
Just verified that <xen: include template="xxxxxx"/> needs to be literal.

You may need to use if statements to include the template you want.
 

Mythotical

Well-known member
#9
Won't work, too many if conditions, basically what I did instead was add <xen:include template="xxxx" /> into the row in the database then tried to pull it but get a blank spot where it should include the template. Am I missing something? Should I have XXXX precached before it gets displayed?
 

Indigo

Active member
#10
For something more complex like this, it sounds like you would want to use a view class to build the HTML of your data list, then store it in a variable which is passed to the template. Sort of like how the settings area in the administration does it.
 

Mike

XenForo developer
Staff member
#11
For something more complex like this, it sounds like you would want to use a view class to build the HTML of your data list, then store it in a variable which is passed to the template. Sort of like how the settings area in the administration does it.
That's exactly the approach needed when the template required is variable.
 

Mythotical

Well-known member
#13
Yeesh, I am so confused now. Too many files to go through to figure this out. Can I get some guidance on specifically which files I should look into for what I need?

Thanks
 

Indigo

Active member
#14
library/XenForo/ViewAdmin/Option/ListOptions.php has an example of it. It loops through a list of options and creates $renderedOptions based on templates, which it then passes to the main template.