XF 2.2 How do I format this link in the template?

AndrewSimm

Well-known member
The values come from $sport, $team, and $year. I can't figure out how to format a link that includes 3 variables. $sport and $team are pulled in with the template and $year is looped through from $years. It is worth noting that the route works fine when I enter the information into the address bar.

Code:
                    <xf:foreach loop="$years" value="$year">
                        <a href="{{ link('players/commits', $sport) }}" class="menu-linkRow u-indentDepth0 js-offCanvasCopy">{$year.name}</a>
                    </xf:foreach>


1641519065246.png
 

Jeremy P

XenForo developer
Staff member
The link builder expects an associative array (or something that can be treated like an associative array, like an entity) with the corresponding route parameters as key/value pairs. You would want to rename the name parameter so it is unique for each fragment (sport_name, team_name, etc.). Then you could do something like this:

HTML:
{{ link('players/commits', {
    'sport_id': $sport.sport_id,
    'sport_name': $sport.name,
    'team_id': $team.team_id,
    'team_name': $team.name,
    'year_id': $year.year_id, 
    'year_name': $year.name
}) }}

Of course that's rather tedious to do more than once, so you could create a method somewhere that builds the array and then call it in your template or pass that through the view parameters.
 
Top