Using a specific block in the footer of all templates
Permalink
I have a page of Tour Dates with each new date being an editable block.
I need to take one of those blocks (it will either be the first or the last block) and display that information in the footer of every page on the site.
I initially just tried doing a database call to get the most recent date:
... but, I realized that even when a block is deleted by an admin on the Tour Dates page, that info is not deleted from the database, so even if that specific block does not reside on the site anywhere, it's still in the database, so it's showing up in my footer.
I see that there is:
$block->alias($page)
and:
$block->duplicate($newPage)
But, I'm not sure if either of these would be the right way to go, or even how they really work.
Any help is greatly appreciated!
I need to take one of those blocks (it will either be the first or the last block) and display that information in the footer of every page on the site.
I initially just tried doing a database call to get the most recent date:
<?php $db = Loader::db(); $r = $db->Execute("SELECT * FROM btTourDates ORDER BY tour_date LIMIT 0, 1"); $row = $r->FetchRow(); ?> <p><span class="label">DATE:</span> <?php $date = new DateTime($row["tour_date"]); echo $date->format( 'F. j, Y' );?><p> <p><span class="label">VENUE:</span> <?php echo $row["venue"];?><p> <p><span class="label">LOCATION:</span> <?php echo $row["city"];?>, <?php echo $row["state"];?><p> <p><span class="label">DETAILS:</span> <?php echo $row["info"];?><p>
... but, I realized that even when a block is deleted by an admin on the Tour Dates page, that info is not deleted from the database, so even if that specific block does not reside on the site anywhere, it's still in the database, so it's showing up in my footer.
I see that there is:
$block->alias($page)
and:
$block->duplicate($newPage)
But, I'm not sure if either of these would be the right way to go, or even how they really work.
Any help is greatly appreciated!
Thanks, Jordan. I think I'm pretty close to getting this. Here is what I have in my footer:
I'm getting the correct block to show up on all pages, but for some reason I can't get the block to use the "footer" template I have setup... Is there something that I'm missing here?
$contentBlocks = array(); $c = Page::getByPath('/dates'); $blocks = $c->getBlocks("Tour Dates"); foreach($blocks as $b) { if ($b->getBlockTypeHandle() == 'tour_date') { $b->display("templates/footer.php"); break; } }
I'm getting the correct block to show up on all pages, but for some reason I can't get the block to use the "footer" template I have setup... Is there something that I'm missing here?
Remove ".php" from the end of the template filename:
$b->display("templates/footer");
$b->display("templates/footer");
That doesn't seem to be doing it either. Also, when I remove ".php" from:
The setCustomTemplate does not work anymore. Maybe I'm doing it wrong... I have a folder called "templates" located in my custom block folder, and within the "templates" folder I have my custom "views" or templates.
Is this how it's supposed to be done?
$lastAreaBlock->setCustomTemplate('templates/last');
The setCustomTemplate does not work anymore. Maybe I'm doing it wrong... I have a folder called "templates" located in my custom block folder, and within the "templates" folder I have my custom "views" or templates.
Is this how it's supposed to be done?
I think so, but like I said, this is a very non-standard way to accomplish this so there isn't going to be a lot of reference or help available.
This is kind of a shot in the dark, but try replacing your "$blockForDisplay->display("template/footer");" line with these lines (so they're all inside that if statement, just before the "break;"):
This is kind of a shot in the dark, but try replacing your "$blockForDisplay->display("template/footer");" line with these lines (so they're all inside that if statement, just before the "break;"):
$blockInstance = $b->getInstance(); $blockForDisplay = Block::getByID($blockInstance->bID); $blockForDisplay->display("template/footer");
Rather than making each date a block on a page, I would make them each a page and use a page list to display them. You could make all the info page attributes to display in the page list. Then a second page list in the footer that displayed either the first or last date. it would just be a quick modification to the page list. You could set an expiration date for each page so events that have passes wouldn't be displayed
How do I create the custom attributes? And the expiration date?
I see the drop-down for custom attributes in the properties pop-up, but how do I make my own to select?
I see the drop-down for custom attributes in the properties pop-up, but how do I make my own to select?
Ok, I think I have created a custom attribute (I read through:http://www.concrete5.org/documentation/how-tos/create-a-custom-attr...
I have it installed as well, but it doesn't show up when I go to myPage>Properties>Custom Attributes.. Not sure what I'm doing wrong.
I have it installed as well, but it doesn't show up when I go to myPage>Properties>Custom Attributes.. Not sure what I'm doing wrong.
Ok, I figured it out. Thanks for the help!
I realized that what I did before (what I posted) was create a new attribute template, which was much more intense than what I needed to do... I still couldn't find documentation on how to create my own custom attributes, but I was able to figure it out by playing around in the admin.
Then I found info on using custom attributes at http://c5mix.com/blog/tips/using-page-attributes-in-concrete5-theme...
I realized that what I did before (what I posted) was create a new attribute template, which was much more intense than what I needed to do... I still couldn't find documentation on how to create my own custom attributes, but I was able to figure it out by playing around in the admin.
Then I found info on using custom attributes at http://c5mix.com/blog/tips/using-page-attributes-in-concrete5-theme...
1) Each event is represented by a PAGE. Create custom attributes to store the information (like date, venue, etc.). Then you would use a Page List block with a custom template to output the event info.
~OR~
2) Create your own database tables to store this data and a model class to access it (optional, but makes code a lot easier to maintain). Create dashboard pages to interact with this data, then create a block that displays this data for a single chosen event (the block edit interface would need to present the data from your custom database tables to the user so they could choose). Then, for your specific situation where you need the most recent date in the footer, just create another custom template for this block that displays it the way you want.
It's going to be a bit of work any way you slice it, which is totally cool if you're into spending time and learning. If you just need to get something out the door, though, it might be worth it to you to buy one of the event addons in the marketplace.
Good luck!
-Jordan