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

xen:link variables in regards to Content Title in URLs

Discussion in 'XenForo Development Discussions' started by AndyB, Nov 18, 2013.

  1. AndyB

    AndyB Well-Known Member

    In my Similar Threads add-on, I display similar results like this:

    pic001.jpg

    The add-on works great when displaying a thread because I can use the $forum variable with the xen:link.

    (this works fine)

    Code:
            <xen:foreach loop="$similarThreads" key="$index" value="$similarThread">
          
                <tr class="dataRow">
                <td><a href="{xen:link forums, $forum}" title="{$similarThread.nodetitle}">{$similarThread.nodetitle}</a></td>
                <td><a href="{xen:link threads, $similarThread}" title="{$similarThread.title}">{$similarThread.title}</a></td>
                <td>{xen:datetime $similarThread.post_date}</td>
                </tr>
          
            </xen:foreach>
    
    However when creating a thread, the $forum variable is out of scope.

    (this doesn't work)
    Code:
            <xen:foreach loop="$similarThreads" key="$index" value="$similarThread">
        
                <tr class="dataRow">
                <td><a href="{xen:link forums, $similarThread}" title="{$similarThread.nodetitle}" target="_blank">{$similarThread.nodetitle}</a></td>
                <td><a href="{xen:link threads, $similarThread}" title="{$similarThread.title}" target="_blank">{$similarThread.title}</a></td>
                <td>{xen:datetime $similarThread.post_date}</td>
                </tr>
        
            </xen:foreach>
    
    I get a forum link that shows the thread title in the URL.
     
    Last edited: Nov 18, 2013
  2. AndyB

    AndyB Well-Known Member

    I was able to resolve this issue using xen:set to change the variable names. It appears that the title is a very important part of using xen:link.

    Code:
            <xen:foreach loop="$similarThreads" key="$index" value="$similarThread">
            
                <tr class="dataRow">
                <xen:set var="$similarThread.title">{$similarThread.nodetitle}</xen:set>
                <td><a href="{xen:link forums, $similarThread}" title="{$similarThread.title}" target="_blank">{$similarThread.title}</a></td>
                <xen:set var="$similarThread.title">{$similarThread.threadtitle}</xen:set>
                <td><a href="{xen:link threads, $similarThread}" title="{$similarThread.title}" target="_blank">{$similarThread.title}</a></td>
                <td>{xen:datetime $similarThread.post_date}</td>
                </tr>
            
            </xen:foreach>
    
     
  3. AndyB

    AndyB Well-Known Member

    Unfortunately the above code doesn't work very well. The problem is that the thread titles with special characters like the ampersand would have code replacements. So I gave up on the idea of having the forum names be links and went with text only on the forum names.
     

Share This Page