Jump to content

API for anchor


Recommended Posts

Hello, is there a method for generating a link on providing the right selector? Something like

<?php echo $pages->get("/mypage/")->link ?>


<a href="/myurl/">mytitle</a>

Instead of writing the whole string

<?= "<a href='".$pages->get("/")->url."'>".$pages->get("/")->title."</a>" ?>


<a href="<?= $pages->get('/')->url"><?= $pages->get("/")->title ?></a>


Link to comment
Share on other sites

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);
			$out = "<a href='".$current->url."'>".$current->title."</a>";
			$out = false;
		return $out;

I haven't tested but should work.

  • Like 3
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...