- concrete5 Cookbook
- David Strack
- 368字
- 2021-08-13 16:15:59
Moving a page
The concrete5 sitemap is a great tool for managing the page hierarchy of your website. It lets you arrange the order of pages, and even drag-and-drop pages to different areas of the site. Thankfully, you aren't limited to using the graphical interface to move pages around the site. You can also rearrange pages dynamically in your custom concrete5 applications.
Getting ready
In this example, we are going to move a Careers page underneath the About Us page. Before we can move a page, we need to have the Page
object of the new parent page that we are moving the current page to.
This exercise assumes that pages exist at both /about
and /careers
in your concrete5 site. You can create those pages through the concrete5 interface, or adapt the code in this recipe to work with pages that exist on your own site.
How to do it...
The steps for moving a page are as follows:
- Open
/config/site_post.php
, as that is a safe place to play with some random code. - First, load the About Us page, which is where the Careers page will be moved to.
- Now, we need to load the careers page that we are moving.
$careersPage = Page::getByPath('/careers');
- Finally, call the
move
function on the careers page, passing it the new parent page and an optional Boolean which tells concrete5 if we want to save the old page path as well as the new one.$careersPage->move($newParent, true);
How it works...
The move function is very easy to use. You only need to provide one parameter, which is a Page
object of the new parent that you are moving the page under. There is an optional second parameter to indicate if you wish to retain the old page path in addition to the current one. That parameter defaults to false.
Once the page is moved, it will inherit the permissions of the new parent page (if the page does not have its own permissions set explicitly).
Once the page is moved, the event on_page_move
is fired.
See also
- Listening to system events in Chapter 9, System Events and Advanced Configuration
- The Getting a Page object by its path recipe
- Kali Linux Web Penetration Testing Cookbook
- LabVIEW2018中文版 虛擬儀器程序設計自學手冊
- Visual C++實例精通
- Getting Started with PowerShell
- Python計算機視覺編程
- Mastering PHP Design Patterns
- Hands-On Full Stack Development with Go
- Scala Reactive Programming
- MongoDB,Express,Angular,and Node.js Fundamentals
- 西門子S7-200 SMART PLC編程從入門到實踐
- JSP程序設計實例教程(第2版)
- 人工智能算法(卷1):基礎算法
- Instant jQuery Boilerplate for Plugins
- scikit-learn Cookbook(Second Edition)
- H5+移動營銷設計寶典