How to get the contents added using block in the default.php to other added sigle pages
Permalink
i have added a block
After that i have added a single page in single page directory called music.php and added the same page name to my themes directory, it is working fine now, my requirement is that i need to fetch the block contents that i have already added for the default.php page, i don't want to add different blocks for my 100 pages.
i tried with this code in music.php
but it is not working, please help.
<?php $a = new Area('Main'); $a->display($c); ?>
After that i have added a single page in single page directory called music.php and added the same page name to my themes directory, it is working fine now, my requirement is that i need to fetch the block contents that i have already added for the default.php page, i don't want to add different blocks for my 100 pages.
i tried with this code in music.php
<?php $page = Page::getCurrentPage(); $pageid = $page->getCollectionID(); if ($pageid == 119) { //Replace XXX for the ID of your page $area= new Area('Main'); if ($c->isEditMode()) { $area->display($c); } else { $blocks = $page->getBlocks('Main'); shuffle($blocks); foreach ($blocks as $b){$b->display();} } } else { $area= new Area('Main'); $area->display($c);
Viewing 15 lines of 16 lines. View entire code block.
but it is not working, please help.
How about using a global area? Than you will only have to add the block to the corresponding stack and it will be available to any page you set up containing this global area. Further reading:http://andrewembler.com/posts/stacks-vs.-scrapbooks/...
Hello,
First things first: you seem to be confusing Areas with Blocks. This code:
just defines an editable Area on your template. Blocks (like forms, images, videos, etc.) are then added to that editable area using the in-context editing.
Secondly, you seem to be confusing single pages with page type templates. The files that live on your theme folder are templates to page types. When you create a new page type, you give it an handle (or machine name) - like "music". When you visit a page of that type, Concrete5 checks the theme folder for a file called "music.php". If it is there, it is used to render the page. If not, default.php is used. People use page types for two reasons - for creating different templates (like in left-sidebar, right-sidebar, etc.) and/or for holding data, in the form of page type attributes.
Now, on your specific issue:
There are at least two ways to share blocks among a lot of pages.
1 - You can define global areas on you template, like this:
Blocks added to global areas will appear on every page that uses that template. When you edit a block that lives in a global area, it is updated everywhere.
2 - You can add the block on the page type default. To edit a page type default, go to Dashboard -> Page Types and click on "Defaults" for the page type you want to edit. Blocks added on page type defaults will be present on every page of that type that is created. When you edit a block that lives on a page type default, a new instance of that block is created for that page, and edits to the block on the page type defaults will no longer affect it.
Maybe it's too much information all at once, but I hope this helps!
First things first: you seem to be confusing Areas with Blocks. This code:
<?php $a = new Area('Main'); $a->display($c); ?>
just defines an editable Area on your template. Blocks (like forms, images, videos, etc.) are then added to that editable area using the in-context editing.
Secondly, you seem to be confusing single pages with page type templates. The files that live on your theme folder are templates to page types. When you create a new page type, you give it an handle (or machine name) - like "music". When you visit a page of that type, Concrete5 checks the theme folder for a file called "music.php". If it is there, it is used to render the page. If not, default.php is used. People use page types for two reasons - for creating different templates (like in left-sidebar, right-sidebar, etc.) and/or for holding data, in the form of page type attributes.
Now, on your specific issue:
There are at least two ways to share blocks among a lot of pages.
1 - You can define global areas on you template, like this:
<?php $a = new GlobalArea('New Global Area'); $a->display(); ?>
Blocks added to global areas will appear on every page that uses that template. When you edit a block that lives in a global area, it is updated everywhere.
2 - You can add the block on the page type default. To edit a page type default, go to Dashboard -> Page Types and click on "Defaults" for the page type you want to edit. Blocks added on page type defaults will be present on every page of that type that is created. When you edit a block that lives on a page type default, a new instance of that block is created for that page, and edits to the block on the page type defaults will no longer affect it.
Maybe it's too much information all at once, but I hope this helps!
ok, i have defined the area in default.php file to
now how i will get the contents for Main area in my music.php file?
<?php $a = new GlobalArea('Main'); $a->display(); ?>
now how i will get the contents for Main area in my music.php file?
Easy - just copy/paste that code to your music.php template.
Also you should give it another name, as some marketplace blocks will use "Main" by default.
Also you should give it another name, as some marketplace blocks will use "Main" by default.
Thanks pmarques , i never knew that i have to add the content again for the global area, it is working now, :)
Glad I could help =)