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

Template inclusion

Discussion in 'XenForo Development Discussions' started by Mythotical, Oct 23, 2010.

  1. Mythotical

    Mythotical Well-Known Member

    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
     
  2. Lawrence

    Lawrence Well-Known Member

    This should work (if it is what you are trying to do):

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

    Mythotical Well-Known Member

    Giving that a try.
     
  4. Mythotical

    Mythotical Well-Known Member

    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]
     
  5. Lawrence

    Lawrence Well-Known Member

    The variables I used in the example foreach I just chose, they are not from your examples.
     
  6. Mythotical

    Mythotical Well-Known Member

    Wait, maybe I need to do it a different way. Let me try another way.
     
  7. Mythotical

    Mythotical Well-Known Member

    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]
     
  8. Lawrence

    Lawrence Well-Known Member

    Just verified that <xen: include template="xxxxxx"/> needs to be literal.

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

    Mythotical Well-Known Member

    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?
     
  10. Indigo

    Indigo Active Member

    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.
     
    CurveGotti likes this.
  11. Mike

    Mike XenForo Developer Staff Member

    That's exactly the approach needed when the template required is variable.
     
    CurveGotti and Kier like this.
  12. Mythotical

    Mythotical Well-Known Member

    Thanks, that is what I needed to know.
     
  13. Mythotical

    Mythotical Well-Known Member

    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
     
  14. Indigo

    Indigo Active Member

    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.
     
  15. Mythotical

    Mythotical Well-Known Member

    Thanks Indigo.
     

Share This Page