- 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
- 從零開始構(gòu)建企業(yè)級(jí)RAG系統(tǒng)
- Spring 5.0 By Example
- 大學(xué)計(jì)算機(jī)基礎(chǔ)實(shí)驗(yàn)教程
- SQL學(xué)習(xí)指南(第3版)
- 技術(shù)領(lǐng)導(dǎo)力:程序員如何才能帶團(tuán)隊(duì)
- Visual Basic學(xué)習(xí)手冊(cè)
- 用Flutter極速構(gòu)建原生應(yīng)用
- Elasticsearch for Hadoop
- Keras深度學(xué)習(xí)實(shí)戰(zhàn)
- Visual Basic程序設(shè)計(jì)
- Python深度學(xué)習(xí)原理、算法與案例
- 用戶體驗(yàn)可視化指南
- 智能搜索和推薦系統(tǒng):原理、算法與應(yīng)用
- Python商務(wù)數(shù)據(jù)分析(微課版)
- Anaconda數(shù)據(jù)科學(xué)實(shí)戰(zhàn)