Jump to content

backend: get whole url in "name" inputfield


pppws
 Share

Recommended Posts

hey there,

 

i know it's a kind of dumb question, but…

is it possible to duplicate the "name" field in the backend and output the whole page URL in the input? i know that i can copy the link when right clicking on it, but just a input field with the whole URL would be more comfortable (in this case).

the second field (ES) illustrates what i mean.

 Screenshot%202017-09-28%2013.14.04.png?d

 

thanks for any help!

Link to comment
Share on other sites

  • 4 weeks later...

Hi pppws, you can do this by defining an extra field e.g. URL as textfield. The you can implement a hook which saves the URL of the page into this field. I've done this for one project. This code can be used within the hellword Module. It's very simple. It saves the URL into the field shortname and fullurl when the user saves the page. In my project the field is locked, but you can define it the way you want. I hope this helps.

	public function init() {

		// add a hook after the $pages->save, to issue a notice every time a page is saved
		$this->pages->addHookBefore('save', $this, 'example1');

	}

	
	public function example1($event) {
		$page = $event->arguments[0];

		if($page->template->name!="presse-post" && $page->template->name!="presse-postev" ) return;

		$page->shortname = wire( "sanitizer" )->pageName( $page->shortname, Sanitizer::translate );
		$page->fullurl   = wire( 'pages' )->get( "/presse/" )->httpUrl() . "r/" . $page->shortname;

	}

 

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
 Share

  • Recently Browsing   0 members

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