Predifined blocks for an area or pre-installed blocks don't work
Permalink
Why if this code inserited in the page_type isn't working? 'page_title' is the handle of the block
$b = new Area('page_title');
$b->setCustomTemplate('page_title', 'view');
$b->display($c);
And also, why this code doesn't load the view.css presents in the same block folder?
$page_title = BlockType::getByHandle('page_title');
$page_title->render('view');
Thanks a lot!
$b = new Area('page_title');
$b->setCustomTemplate('page_title', 'view');
$b->display($c);
And also, why this code doesn't load the view.css presents in the same block folder?
$page_title = BlockType::getByHandle('page_title');
$page_title->render('view');
Thanks a lot!
nobody knows why the view.css hasn't loaded togheter with its view.php?
You're passing in "view" for the custom template name, but "view" is just the default template so there's no difference between using that code and not using the code.
And which folder is the view.css file in?
And which folder is the view.css file in?
view.php e view.css are in the same folder. It doesn't work either I use render('view') or render('templates/nome_templ/view'). In both cases the template is loaded but without its related css (that is always in the same block folder or 'template/nome_temp/' folder).
So, the problem is:
- setCustomTemplate doesn't install the block in the Area by default and
- 'BlockType::getByHandle() ... ->render().. ' block of code, installs the block but without applying the css
So, the problem is:
- setCustomTemplate doesn't install the block in the Area by default and
- 'BlockType::getByHandle() ... ->render().. ' block of code, installs the block but without applying the css
Try render('templates/nome_templ')
yet tried and doesn't work. It works only if I've already set the block on the page. But in this way that code is quite useless because it become only not editable ...
never had this problem or never used this feature?
both -- sorry :(
no probl, thanks!
But what I can do if I want to create by code a page with some blocks installed on?
But what I can do if I want to create by code a page with some blocks installed on?
The code you had looked like it was trying to display blocks that already exist, not create pages and put blocks in them. What is it exactly you're trying to achieve?
of course, in that case I want to put some block directly in the page. But I think that I could use that code to install blocks in a page created by code, couldn't I?
Sorry, but I just am not clear on what it is exactly you want to do -- can you give me an example with some more context?
ok sorry. I asked for that code because, meanwhile I'm only creating the blocks for may site, I add new pages simply by dashboard to see how is the final result (then the different will be only in the information showed). Some areas, however, repeat themselves in many pages so I tried that code in order to avoid to repeat the blocks installation steps.
After that, I think that code could be useful when I'll have to add pages by code (instead of by dashboard) and I'll have to create that pages with some blocks already installed. Is it correct? Otherwise, how can I to that?
After that, I think that code could be useful when I'll have to add pages by code (instead of by dashboard) and I'll have to create that pages with some blocks already installed. Is it correct? Otherwise, how can I to that?
If you want blocks to appear repeatedly on new pages, use the "Page Defaults" feature -- go to Dashboard -> Pages and Themes -> Page Types, click the "Defaults' button next to the page type you want to put the default blocks on.
If you want to create pages in code and add blocks to them, use the API -- for example:
If you want to create pages in code and add blocks to them, use the API -- for example:
$parentPage = Page::getByID(999); //set this to the parent page that the new page will be added under (use 1 if this page should be at the top-level of the site) $newPageName = 'My New Page'; $newPageTypeHandle = 'my_page_type_handle'; Loader::model('collection_types'); $newPage = $parentPage->add(CollectionType::getByHandle($newPageTypeHandle), array('name' => $newPageName)); //If you need to set custom attributes, uncomment and modify the following line: //$newPage->setAttribute(CollectionAttributeKey::getByHandle('attribute_handle'), 'some value'); $contentBlockType = BlockType::getByHandle('content'); $pageAreaHandle = 'Main'; $newPageContent = '<p>Blah blah blah, some page content</p>'; $newPage->addBlock($contentBlockType, $pageAreaHandle, array('content' => $newPageContent)); //If you need the new page CID... echo $newPage->getCollectionID();
Ok right! I will use the first suggestion and I will try with the second!
Thanks for the help!
Thanks for the help!