Calling the block using php
Permalink Browser Info Environment
Hi - this is a really useful addon - thanks for posting it. We want to run it from php, setting the file set name programmatically. Do you have a code sample to help us along the way?
Thanks again
Thanks again
Type: | Discussion |
---|---|
Status: | Resolved |
Hi - thanks for that. I probably wasn't clear. What I was after was an example of the parameters for a block call from php - so, for example,
Sorry if it wasn't clear.
$blockType = BlockType::getByHandle('list_files_from_set'); //parameters passed here $blockType->render('view');
Sorry if it wasn't clear.
Ah, you mean hard-coding the block into a page.
What you have should work, you can adjust settings by adding in before your render line, things like:
$blockType->controller->fileOrder = 'set_order';
For the different things you _might_ be able to adjust, have a look at the db.xml and at the database fields the block uses.
You might also want to look at this blog post as well, it might give you a good example of what to do -http://www.mesuva.com.au/blog/concrete5/creating-a-composer-driven-...
This kind of approach works in 5.6, but I haven't hard coded the block in 5.7 yet. Hopefully the same code still works.
What you have should work, you can adjust settings by adding in before your render line, things like:
$blockType->controller->fileOrder = 'set_order';
For the different things you _might_ be able to adjust, have a look at the db.xml and at the database fields the block uses.
You might also want to look at this blog post as well, it might give you a good example of what to do -http://www.mesuva.com.au/blog/concrete5/creating-a-composer-driven-...
This kind of approach works in 5.6, but I haven't hard coded the block in 5.7 yet. Hopefully the same code still works.
Hi - just to let anyone who's wanting to do the same know, the code below works ok;
Many thanks for your help and for such a useful addin.
Loader::model('file_set'); //get the file set object as $fs $blockType = BlockType::getByHandle('list_files_from_set'); $blockType->controller->fsID = $fs->getFileSetID(); // set the file set ID to the ID of the file set object $fs $blockType->controller->numberFiles=10; //set the number of files to display $blockType->controller->paginate='true'; $blockType->render('view');
Many thanks for your help and for such a useful addin.
if you're wanting to change the way the block outputs the file names, what you need to do is override the block's template, or create a custom block template for it (so you can pick when you use it).
You would need to:
- Create in the top level /application/blocks folder, a folder called list_files_from_set.
- In that, copy in the view.php from the list files from set package and them make changes to that version, which will override what it outputs.
Alternatively, you can create the folder /application/blocks/list_files_from_set/templates and in that copy in the view.php, but rename it to something else. Then you can pick what you've copied in as a custom template when you are editing a block, see -http://www.concrete5.org/documentation/using-concrete5-7/in-page-ed...
If you haven't overridden blocks before, you may need to look up a general guide on how to do that.
-Ryan