Manaus Posted September 19, 2021 Share Posted September 19, 2021 Hello, is there a method for generating a link on providing the right selector? Something like <?php echo $pages->get("/mypage/")->link ?> generating <a href="/myurl/">mytitle</a> Instead of writing the whole string <?= "<a href='".$pages->get("/")->url."'>".$pages->get("/")->title."</a>" ?> or <a href="<?= $pages->get('/')->url"><?= $pages->get("/")->title ?></a> Thanks! Link to comment Share on other sites More sharing options...
Andy Posted September 19, 2021 Share Posted September 19, 2021 Hi @Manaus Why don't you use a function? <?php namespace ProcessWire; /* * * /site/templates/_func.php * use include_once in your code template */ function my_render_link($selector) { $current = wire('pages')->get($selector); if($current->id){ $out = "<a href='".$current->url."'>".$current->title."</a>"; }else{ $out = false; } return $out; } ?> I haven't tested but should work. 3 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now