Coding and more – Concrete5, Flex, JavaScript

concrete5 – programmatically creating a page alias

in concrete5 you can create an alias if you want a page to appear at two different locations. If you look at the following site structure, you can see that we have two categories and two different services we’d like to offer.

alias_1

For whatever reason, we’d like to make sure that our main service shows up beneath both categories. It’s physical location is right under the first category but how do we add an alias underneath the second category? In the UI this is super easy, just drag the service to the second category and release the mouse button – a dialog will show up where you can select that you want to create an alias and that’s it! But how do we the same using code? It’s also pretty simple:

1
2
3
4
<?php
$pageToAlias = Page::getByPath('/category-1/service');
$parentOfAlias = Page::getByPath('/category-2');
$newAlias = $pageToAlias->addCollectionAlias($parentOfAlias);

I’ve used Page::getByPath to get both page objects but you can of course use Page::getByID or anything else that returns a valid page object. As soon as you’ve run this code, you’ll have an alias in your sitemap like that:

alias_2

2 Responses to “concrete5 – programmatically creating a page alias”

  • Tilde Gundel

    Dear Remo

    I have with interest been looking at your code for creating alias pages.

    The case is that I want to create something similar that but instead of alises I want to duplicate the page to a new position in the sitetree.
    (This is due to the use of next/prev on pages, which as you know relates to pages with the same parent and on the same level)
    Also I want to add a condition.

    I have tried different solutions, but can’t seem to make it work. I have posted in the Concrete5 forum for support, but haven’t recieved any feedback.
    http://www.concrete5.org/community/forums/customizing_c5/programmatically-duplicate-a-page-to-a-new-position-in-sitetree-/
    In desperation, I even contacted Michael from concrete5.dk, but to no avail.

    Could you help me this???
    I am of course willing to pay for your time and service.

    I will be looking forward to hearing from you

    best wishes
    Tilde / Copenhagen, Denmark +45 28718057

  • Leave a Reply