- 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.
$newParent = Page::getByPath('/about');
- 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
- Spring 5企業(yè)級開發(fā)實戰(zhàn)
- 零起步玩轉掌控板與Mind+
- Getting Started with ResearchKit
- 碼上行動:零基礎學會Python編程(ChatGPT版)
- Hands-On RESTful Web Services with Go
- 手把手教你學C語言
- Python算法從菜鳥到達人
- SQL Server從入門到精通(第3版)
- Extending Puppet(Second Edition)
- Create React App 2 Quick Start Guide
- Java并發(fā)編程之美
- 零代碼實戰(zhàn):企業(yè)級應用搭建與案例詳解
- Instant Automapper
- 第五空間戰(zhàn)略:大國間的網絡博弈
- 分布式系統(tǒng)架構與開發(fā):技術原理與面試題解析