Add Canonical URL when Creating Page Programmatically
Permalink
I'm creating some pages programmatically with the following code, but I can't seem to find the correct reference for Canonical URL, or the page URL. I want to make it different than the title of the page.
I thought it would be $data['cURL'] as shown above. But that doesn't work.
Any suggestions?
Loader::model('collection_types'); $path = "/resources/newpage"; $newPage = Page::getByPath($path); $data = array(); $data['cName'] = $title; $data['cDescription'] = $title. " " .$date; $data['cURL'] = $pageURL; $ct = CollectionType::getByHandle('right_sidebar'); $newPage->add($ct, $data);
I thought it would be $data['cURL'] as shown above. But that doesn't work.
Any suggestions?
I think you want 'cHandle' (note that this must be a relative URL, for example "/about/people", not "http://example.com/about/people")
hi,
i setup a package with a template, blocks and a single page. everything works fine.
now i add the code above to the package controller, but i get an error.
Call to a member function getPackageID() on a non-object in F:\Server\xampp\htdocs\projekte\C5-Developer\concrete\models\page.php on line 1943
here is the code i add to the controller
did i miss something?
thanks for your help
i setup a package with a template, blocks and a single page. everything works fine.
now i add the code above to the package controller, but i get an error.
Call to a member function getPackageID() on a non-object in F:\Server\xampp\htdocs\projekte\C5-Developer\concrete\models\page.php on line 1943
here is the code i add to the controller
Loader::model('collection_types'); $path = "/"; $pr = Page::getByPath($path); $data = array('cName'=>'Hallo Welt', 'cDescription'=>'Testet einfach drauf los', 'cHandle'=>'halle-welt'); $ct = CollectionType::getByHandle('right_sidebar'); $pr->add($ct, $data);
did i miss something?
thanks for your help
I don't see anything strange in the specific code snippet you posted -- can you please post the entire contents of your package's controller.php file (might be easiest to ZIP it and post that as an attachment)? I think the problem might be somewhere else in the file.
Also, are you getting this error when you try to install the package, or some other time (like when a page is viewed or edited)?
Also, are you getting this error when you try to install the package, or some other time (like when a page is viewed or edited)?
I think the problem may be this line:
The autonav block is already installed as part of the core C5 system -- you cannot have another block with the same name.
Is this just for some custom template files? If so, you don't need to do anything in the install function -- as long as they're in the proper place ( YOURSITE/packages/henrich_parkett_pack/blocks/autonav/templates/ ).
Or did you create another block called "autonav"? If so, you need to rename it.
BlockType::installBlockTypeFromPackage('autonav', $pkg);
The autonav block is already installed as part of the core C5 system -- you cannot have another block with the same name.
Is this just for some custom template files? If so, you don't need to do anything in the install function -- as long as they're in the proper place ( YOURSITE/packages/henrich_parkett_pack/blocks/autonav/templates/ ).
Or did you create another block called "autonav"? If so, you need to rename it.
hi,
the autonav is only for the custom template on a fresh installation of C5. I found the problem with the page installation. i forgot to install the page-type i want to use. but now i run into another problem.
i love Concrete5 for this "learning by doing feature" ^^
the autonav is only for the custom template on a fresh installation of C5. I found the problem with the page installation. i forgot to install the page-type i want to use. but now i run into another problem.
i love Concrete5 for this "learning by doing feature" ^^
Where / when are you getting that error? Please post code.