#1 2013-08-08 14:43:38

jeremy
Member
Registered: 2013-08-08
Posts: 7

Get Parent page of an another page

Hello Everybody,

I have a hierarchy like this:

Page 1
-> SubPage 1.1
Page 2
-> SubPage 2.1

Can I retrieve the "Page 1" link from "SubPage 1.1" with an ion Tag ?

Thanks

Last edited by jeremy (2013-08-09 14:06:33)

Offline

#2 2013-08-08 19:01:51

salgua
Member
From: Italy
Registered: 2013-04-11
Posts: 60

Re: Get Parent page of an another page

Hi,

you can see the full list of available keys using <ion:article:trace /> or <ion:page:trace />. Than you can retrieve a key value using <ion:get key="keyname" />

Last edited by salgua (2013-08-08 19:02:06)

Offline

#3 2013-08-09 07:38:59

Kink
Ion Tester
From: France
Registered: 2010-06-04
Posts: 581

Re: Get Parent page of an another page

What about using <ion:breadcrumb /> tag ?
Little trick not explain in the doc, you can put <ion:breadcrumb article="true" /> to display the current article (not linked)


Webmaster / OUF!WEB

Offline

#4 2013-08-09 09:55:53

jeremy
Member
Registered: 2013-08-08
Posts: 7

Re: Get Parent page of an another page

Thanks for your reply.

@king: In this case breadcrumbs tag is not the solution because I'm not in a article, but in a page.

@salgua:
Yest with <ion:get key="keyname" />, I can get the parent id smile,
I had not yet understood the value of this tag

My goal is create a back link.
I don't know is the best solution but I use this code and it work:

<?php
$parent_id = '<ion:page:get key="id_parent" />';
?>
<ion:page id="<?php echo $parent_id; ?>
<ion:url/>
</ion:page>

This code may seem buged but if I write

<ion:page id="<?php echo $parent_id; ?>">, the code return
"> <url_of_the_parent_page>

Do you have a better solution ?

Last edited by jeremy (2013-08-09 09:56:38)

Offline

#5 2013-08-09 10:13:07

salgua
Member
From: Italy
Registered: 2013-04-11
Posts: 60

Re: Get Parent page of an another page

Pay attention that Ionize first parse the <ion:xxx> tags then evaluate the php code. This means that you cannot include php code in ion tags. I cannot understand as <ion:page id="<?php echo $parent_id; ?>"> can work...

Last edited by salgua (2013-08-09 10:13:35)

Offline

#6 2013-08-09 10:22:16

jeremy
Member
Registered: 2013-08-08
Posts: 7

Re: Get Parent page of an another page

OK thanks,

I have an url smile in return.

What the best solution, because, I can't write

<ion:page id="<ion:page:get key="id_parent" />">
<ion:url/>
</ion:page>

It doesn't work.

For the moment i can get de parent id, but how I can get a parent url ?

Offline

#7 2013-08-09 10:23:10

Kink
Ion Tester
From: France
Registered: 2010-06-04
Posts: 581

Re: Get Parent page of an another page


Webmaster / OUF!WEB

Offline

#8 2013-08-09 14:05:11

jeremy
Member
Registered: 2013-08-08
Posts: 7

Re: Get Parent page of an another page

It doesn't work sad,

with <ion:navigation level="0"> I have all pages in the first level, is not necessary the parent page.

In
Page 1
-> SubPage 1.1
Page 2
-> SubPage 2.1

I just want:
<a href="<Page1 url">Back</a>

if I'm in  SubPage 1.1

I try again to later with <ion:navigation and <ion:tree_navigation.

Last edited by jeremy (2013-08-09 14:05:50)

Offline

#9 2013-08-09 14:34:05

Kink
Ion Tester
From: France
Registered: 2010-06-04
Posts: 581

Re: Get Parent page of an another page

You can't do that : <ion:page id="<?php echo $parent_id; ?> because php is computed after ionize code.
A way to search : url segment, with current_url()... and delete last segment ??!??


Webmaster / OUF!WEB

Offline

#10 2013-08-12 02:35:09

damascus
Member
From: Brisbane, Australia
Registered: 2013-04-08
Posts: 270
Website

Re: Get Parent page of an another page

Helper function - string manipulation of url

You could just apply a php str manipulation to remove the last uri segment from the url, leaving you (assumingly) with the parent url, using base_url as a check against top level pages.


Tagmanager approach

This might not 'always' be the best solution (if you want to expand functionality to certain use cases), in which case i would recommend something like this:

/application/libraries/Tagmanager/Page.php

// CHANGED new tags defined
	public static $tag_definitions = array
	(
	   'pages' =>  'tag_pages',
	...
           'page:parent_url' =>  'my_tag_parent_url',

	);

  // ------------------------------------------------------------------------

  // CHANGED returns the absolute url of parent page, or '' if no parent
  public static function my_tag_parent_url(FTL_Binding $tag)
  {
    $page = $tag->get('page');
    
    if (is_null($page))
      $page = self::$context->registry('page');
    
    $id_parent = $page['id_parent'];
    $parent = (isset($id_parent) && $id_parent > 0) ? self::get_page_by_id($id_parent) : null;
    
    $value = (is_null($parent)) ? '' : $parent['absolute_url'];

    return self::output_value($tag, $value); 

  }

And to see its effects:

\themes\frontend\views\...\header.php

<ion:page:parent_url/>


Simple function which return the parent url, or an empty string '' if no parent is found.

It would prob be simpler to just create a helper to use php string manipulation, something like explode('/',$url), indexOf then substr the desired length.

But if you want there is the tag approach too. The advantage being that if you really wanted, you could tweak it with functionality already present in other Page functions, such as get_breadcrumb_array, and have it respond to attributes like 'level' to allow more fine-grained approach, though you should be able to replicate that with simple string manipulation anyway wink


My Recommendation

The main to do the tag approach would be to gain better familiarity with tag system and if you wanted to expand it with functionality present in other tags.

Id personally recommend simply making the helper function, much easier and uses simple php.


Regards,
Damascus

Last edited by damascus (2013-08-12 06:53:58)


Webmaster | OneCNC Australia

Offline

#11 2013-08-12 12:32:17

jeremy
Member
Registered: 2013-08-08
Posts: 7

Re: Get Parent page of an another page

Thanks damascus,

It Works smile,

I'll look more tags,  the only thing is when the update inoize.

Jérémy

Offline

#12 2013-08-31 17:55:27

Michel-Ange
Ionize Core Team
From: Paris, France
Registered: 2010-03-22
Posts: 927
Website

Re: Get Parent page of an another page

@damascus :
Your "my_tag_parent_url" tag approach is good, but limits to the first parent, and of course to the URL of the page.

@jeremy :
I suggest using the <ion:page /> tag for this, and getting the parent from this tag :

<ion:page:url parent="-1" />

This wasn't documented, I corrected the doc to add this very useful feature : http://doc.ionizecms.com/en/tags-reference/page-tags


Inspiration & Innovation : Websites by Partikule, Agence Web Paris

Offline

#13 2013-09-05 16:01:17

jeremy
Member
Registered: 2013-08-08
Posts: 7

Re: Get Parent page of an another page

Thanks Michel-Ange

Offline

#14 2015-10-30 13:49:54

fredericomarinho.com
Member
From: Juiz de Fora / Brazil
Registered: 2015-06-08
Posts: 40
Website

Re: Get Parent page of an another page

<ion:page parent="true">
<ion:url/>
</ion:page>


Frederico Marinho - Social Media and Web Developer
contato@fredericomarinho.com
fredericomarinho.com

Offline

What's Ionize ?

Ionize is an Open Source Content Management System created by webdesigners for webdesigners.

Created and maintained by Partikule and Toopixel, Ionize wants to be the easiest and most powerful CMS.

Can I help ?

Because talent is nothing without involvement, we are looking for motivated coders and webdesigners to join the project team.

Resources

Website : ionizecms.com
Documentation : doc.ionizecms.com

Development : Ionize on GitHub
Translations : Ionize Translations