XF 2.0 Using {{ link('') }}

AndrewSimm

Well-known member
Throughtout XF I see the links are built usign {{ link('page', $var) }}. I am trying to understand how the variable is used within the link. if you look at my code below, I can get it to work when I do <a href="/articles/categories/{$category.category_id}/delete" but I know that should be {{ link('articles/categories', $categories) }}. The problem is that is not working for me and I do not know why.

HTML:
<xf:foreach loop="$categories" value="$category">
    <tr class="dataList-row">
        <td class="dataList-cell dataList-cell--link">
            <a href="{{ link('articles/categories/', $category) }}" />{$category.category}</a>
        </td>
        <xf:if is="{{ $xf.visitor.hasPermission('andrew_articles', 'canEditCategory') }}">
            <td class="dataList-cell dataList-cell--action">
                <a href="{{ link('articles/categories/edit', $category) }}" class="dataList" data-xf-click="overlay" data-original-title="Edit">Edit</a>
            </td>
        </xf:if>
        <xf:if is="{{ $xf.visitor.hasPermission('andrew_articles', 'canDeleteCategory') }}">
            <td class="dataList-cell dataList-cell--action">
                <a href="/articles/categories/{$category.category_id}/delete" class="dataList" data-xf-click="overlay" data-original-title="Delete">Delete</a>
            </td>
        </xf:if>
    </tr>
</xf:foreach>
 
Consider you have the following route structure:
189382

When using {{ link }} you firstly need to specify the first part of your URL, which consists of "Route prefix" and "Sub-name" so:
HTML:
{{ link('conversations/messages

That is all. As you can see we already specified route prefix and sub name. That means that after that XenForo will automatically put integer message_id.

If so, the only thing you need to do: specify an action:
HTML:
{{ link('conversations/messages/delete

Finally, you need to provide an entity from which message_id will be retreived and placed between messages/ and delete:
HTML:
{{ link('conversations/messages/delete', $message) }}

-----

In your case:
HTML:
{{ link('articles/categories/delete', $category) }}
 
Last edited:
Consider you have the following route structure:
View attachment 189382

When using {{ link }} you firstly need to specify the first part of your URL, which consists of "Route prefix" and "Sub-name" so:
HTML:
{{ link('conversations/messages

That is all. As you can see we already specified route prefix and sub name. That means that after that XenForo will automatically put integer message_id.

If so, the only thing you need to do: specify an action:
HTML:
{{ link('conversations/messages/delete

Finally, you need to provide an entity from which message_id will be retreived and placed between messages/ and delete:
HTML:
{{ link('conversations/messages/delete', $message) }}

-----

In your case:
HTML:
{{ link('articles/categories/delete', $category) }}

Perfect explanation. I got it working.
 
Top Bottom