PHP code for including a block
Permalink
Is there any way to include a block without making an area for it.
For example, I am wanting to have a search box at the top of every page, but I do not want it to be an area/editable. I want to keep what is editable to a minimum (main target is simply the page). It would be ideal to be able to include it in the PHP of the main layout.
Now before you all ask why am I using a CMS, I find c5 is very easy and intuitive so I can deploy and let others edit, but there are so many tweakers, I would prefer to have some blocks un-editable.
Thanks in advance.
For example, I am wanting to have a search box at the top of every page, but I do not want it to be an area/editable. I want to keep what is editable to a minimum (main target is simply the page). It would be ideal to be able to include it in the PHP of the main layout.
Now before you all ask why am I using a CMS, I find c5 is very easy and intuitive so I can deploy and let others edit, but there are so many tweakers, I would prefer to have some blocks un-editable.
Thanks in advance.
the only problem i see with the seconds one is that they maybe able to delete or modify it but i would not use the first example
Thanks for your replies.
Jens, because I want to include more than a search box, I am leaning towards your second suggestion.
I am still learning, so I think I will try and find if you can put this in a tag for readability.
Jens, because I want to include more than a search box, I am leaning towards your second suggestion.
I am still learning, so I think I will try and find if you can put this in a tag for readability.
Thanks Jens, that's exactly what I was needing for a site I am currently working on. I've been wanting to embed the autonav block so that the end user has less opportunity to modify / accidentally remove key parts of the site.
If anyone else is attempting to do this, something I found handy was to create an autonav instance with the configuration you are wanting through the UI. Then, find it's record in the btNavigation table, and copy the settings from there.
Dan
If anyone else is attempting to do this, something I found handy was to create an autonav instance with the configuration you are wanting through the UI. Then, find it's record in the btNavigation table, and copy the settings from there.
Dan
Hi Chiscorp,
I've only been using concrete5 for a few days (but am quickly becoming an evangelist) and have solved this same issue with Advanced Permissions.
This means that I have configured my site to allow me as admin to modify a block i.e. search, navigation, breadcrumb but this is not available to those in my 'Editor' group and simply doesn't come up as editable in their view.
This non-code approach strikes me as better practice unless I've missed something here as it allows you to make changes easily using a standard approach and not code.
Anyhow, that's my two cents.
Regards,
Dan
I've only been using concrete5 for a few days (but am quickly becoming an evangelist) and have solved this same issue with Advanced Permissions.
This means that I have configured my site to allow me as admin to modify a block i.e. search, navigation, breadcrumb but this is not available to those in my 'Editor' group and simply doesn't come up as editable in their view.
This non-code approach strikes me as better practice unless I've missed something here as it allows you to make changes easily using a standard approach and not code.
Anyhow, that's my two cents.
Regards,
Dan
I agree that it's best to use permissions and avoid writing code in many situations. But there are some other situations where using the code might be a better solution -- for example, I am designing a template for a client but the site hasn't been deployed yet. So I want to add the block in code so I know it will definitely be there upon deployment (that is, I don't want to have to remember to go to all of the pages the block is supposed to be on, add the block, then set permissions). Of course I will have to remember to install the block upon installation, but reducing the "things to remember upon deployment" list to just "install all custom blocks" is much simpler.
-Jordan
-Jordan
Update: Well, it turns out you can't really achieve what I wanted (including a block directly in the template for ease-of-deployment purposes), because:
For my purposes I don't want to include a database ID of the block because that would imply having to add the block via admin interface after deployment. So I just put the code to place the block in the template directly (as specified here:http://www.concrete5.org/index.php?cID=28147... and here:http://www.concrete5.org/index.php?cID=29221... ). BUT this didn't wind up working because random strange things were happening due to this being a "detached" block (not having a corresponding database record) -- most notably, I had a form in the view and when I called the $this->action() function, nothing was outputted, so forms were useless.
I guess in this case I just need to add it to the page template itself and put a controller in /controllers/page_types/PAGETYPENAME.php
-Jordan
For my purposes I don't want to include a database ID of the block because that would imply having to add the block via admin interface after deployment. So I just put the code to place the block in the template directly (as specified here:http://www.concrete5.org/index.php?cID=28147... and here:http://www.concrete5.org/index.php?cID=29221... ). BUT this didn't wind up working because random strange things were happening due to this being a "detached" block (not having a corresponding database record) -- most notably, I had a form in the view and when I called the $this->action() function, nothing was outputted, so forms were useless.
I guess in this case I just need to add it to the page template itself and put a controller in /controllers/page_types/PAGETYPENAME.php
-Jordan
[quote]I guess in this case I just need to add it to the page template itself and put a controller in /controllers/page_types/PAGETYPENAME.php[/quote]
I had the same problem Jordon, so I quit for the time being and started using another CMS. This is my only problem with c5! Please could you give me some more information on what you did exactly. I wanted to start writing controllers etc but I don't know the code well enough to do it without lots of trial and error.
I had the same problem Jordon, so I quit for the time being and started using another CMS. This is my only problem with c5! Please could you give me some more information on what you did exactly. I wanted to start writing controllers etc but I don't know the code well enough to do it without lots of trial and error.
Sure! Have a look at this documentation:http://www.concrete5.org/help/building_with_concrete5/developers/mv...
It starts off talking about single pages, but if you scroll down a bit there's a section called "Using Controllers with Page Types Instead of Single Pages", which explains pretty nicely how you can set up a controller for a page type (so that it can respond to a form on your template).
One potential problem is if you want to create a database table to store data for this controller -- but it looks like if you put this into a package, that will allow you to have an installable db.xml file for the schema (seehttp://www.concrete5.org/help/building_with_concrete5/developers/pa... for more details -- if you simply include a "db.xml" file in the root directory of your package it will be installed automatically when the package is installed via the dashboard).
I hope that explains it for you -- if not feel free to reply and I can try to explain it better. Good luck!
It starts off talking about single pages, but if you scroll down a bit there's a section called "Using Controllers with Page Types Instead of Single Pages", which explains pretty nicely how you can set up a controller for a page type (so that it can respond to a form on your template).
One potential problem is if you want to create a database table to store data for this controller -- but it looks like if you put this into a package, that will allow you to have an installable db.xml file for the schema (seehttp://www.concrete5.org/help/building_with_concrete5/developers/pa... for more details -- if you simply include a "db.xml" file in the root directory of your package it will be installed automatically when the package is installed via the dashboard).
I hope that explains it for you -- if not feel free to reply and I can try to explain it better. Good luck!
btw, you don't necessarily need to make a package if you just to add some more tables. try adding a database schema to /config/site_db.xml, and then add this global variable declaration to /config/site.php:
define('ENABLE_DEVELOPER_OPTIONS', true);
then there should be an easy way to refresh your tables via the /dashboard/settings/ page.
define('ENABLE_DEVELOPER_OPTIONS', true);
then there should be an easy way to refresh your tables via the /dashboard/settings/ page.
Create a page/destination with a search block, to show results, like "/search", and use a <form> like this in your header:
but.. if you want to call a block inside a template, do like this (autonav example), you can find the blocktype, and block elements in your database (phpmyadmin).
/Jens Griebel