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

XF 1.5 Passing variables to templates?

Discussion in 'Styling and Customization Questions' started by Helixion, Sep 8, 2015.

  1. Helixion

    Helixion Member

    Hello, I'm currently using xenporta, and I want to pass a variable to the page_container template.

    Currently I'm using this snippet of code:
    <xen:if is="{$contentTemplate} == 'EWRporta2_ArticleView' || {$contentTemplate} == 'thread_view'">
                    <div class="userAvatar">
                       <xen:avatar user="$posts.{$thread.first_post_id}" size="s" />
    and with css, it would position the avatar of the first poster (which in this case is author) to the left of the topic title. Unfortunately $posts doesn't seem accessible to page_container.

    So my question is how would I make it so page_container can access $posts?
  2. Arty

    Arty Well-Known Member

    You can't use variables from content template inside container without passing them to container. Use something like this in content template:
    <xen:container var="$first_post_id">{$thread.first_post_id}</xen:container>
    then you can use variable {$first_post_id} in page_container.
  3. Helixion

    Helixion Member

    hey thanks for the help, which content template should I pass the variable from however? I used EW2porta_ArticleView / List but that didn't seem to do anything? Where do the $posts / $thread variables come from?
  4. Arty

    Arty Well-Known Member

    From wherever those variables exist. You posted that code, so I assumed you knew what those variables were and simply had issues accessing them. Don't use code I posted literally, use it as example on how to modify your code.

    I suggest creating that whole div inside content template, then assigning it to container variable. Then in container template simply use {xen:raw $whatever} to display that code.

Share This Page