XF 2.0 How to build canonical link to an admin route

Sim

Well-known member
How can I generate a canonical link to an admin route using a template function in an email template?

For example, in an admin template, {{ link('canonical:tools') }} generates the expected http://example.com/admin.php?tools/

However, in an email template, it assumes a public route and generates: http://example.com/index.php?tools

How can I force it to generate an admin link?
 

Jake B.

Well-known member
Not sure about in public/email templates, but you can use \XF::app()->router('admin')->buildLink('tools') to generate the link and use that as a parameter in your email
 

Sim

Well-known member
Not sure about in public/email templates, but you can use \XF::app()->router('admin')->buildLink('tools') to generate the link and use that as a parameter in your email

Yes, that's what I'm doing now - but it would be nice to have a template function which avoids the need to do that for email templates.
 

Jake B.

Well-known member
Yes, that's what I'm doing now - but it would be nice to have a template function which avoids the need to do that for email templates.

Actually, have a look at the "actions" dropdown on the edit user page, there is a link to view public profile there from an admin template. Might be able to do something similar to get an admin link from a public/email template. Don't have an install anywhere near me right now just happened to think of this while on mobile
 
  • Like
Reactions: Sim

Sim

Well-known member
Actually, have a look at the "actions" dropdown on the edit user page, there is a link to view public profile there from an admin template. Might be able to do something similar to get an admin link from a public/email template. Don't have an install anywhere near me right now just happened to think of this while on mobile

That's exactly what I'm looking for - thanks!

{{ link_type('admin', 'tools') }} works as expected in an email template.
 
Top