xen:link variables in regards to Content Title in URLs

AndyB

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

pic001.webp

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:
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>
 
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.
 
Top Bottom