Calling developers - post your block embed code snippets

Permalink 9 users found helpful
Hi There,

Being a designer, I've spent days trying to figure out block embed code by inspecting block edit windows in firebug. Yep, that's the best I can do!

I thought it might be helpful to create a bit of a repository - these are the ones I've figured out so far...

SEARCH BLOCK EMBED CODE:
<form action="<?php echo View::url('/search'); ?>" method="get">
    <input type="text" name="query" class="" title="Search" />
    <input type="submit" name="submit" value="Search" class="" />
</form>


TAGS BLOCK EMBED CODE:
<?php
    $tagsBT = BlockType::getByHandle('tags'); // get an instence of the tags block and name it $tagsBT
    $tagsBT->controller->attributeHandle = "tags"; // attribute handle of the tags to display
    $targetPage = Page::getByPath('/projects/project-search-results'); // when you click a tag, this is the page that displays the results - must contain a search block and must be a valid page or no tags will display
    $tagsBT->controller->targetCID = $targetPage->getCollectionID(); // links tags to the $targetPage above
    $tagsBT->controller->displayMode = 'cloud'; // possible modes: cloud = displays all tags / page = displays tags assigned to the current page only
    $tagsBT->controller->cloudCount = '10'; // number of tags to display when using cloud displayMode above
    $tagsBT->render('templates/sidebar/view'); // display template used to control how the tags render
?>


PAGELIST BLOCK EMBED CODE:
<?php
   $pagelistBT = BlockType::getByHandle('page_list'); // grabs the page list block and sets it as the object $pagelistBT in this instance
   $pagelistBT->controller->cThis = ''; // display pages under the current page (I think) - 0 = no, 1 = yes
   $pagelistBT->controller->cParentID = '136'; // if another page enter its ID (cid) - 0 must be entered above for cThis
   $pagelistBT->controller->ctID =''; // only show pages of a particular type(collection Type ID)
   $pagelistBT->controller->num = ''; // amount to display on a single page
   $pagelistBT->controller->orderBy = 'display_asc'; // display_asc = Display order ascending, display_desc = Display order descending, chrono_asc = Publish date, alpha_asc = By name ascending, alpha_desc = By name descending
   $pagelistBT->controller->rss = ''; // provide a RSS feed of the pages - 0 = no, 1 = yes
   $pagelistBT->controller->displayFeaturedOnly = ''; // displays only pages with an attribute of is_featured uses a boolean value - 0 = no, 1 = yes
   $pagelistBT->controller->displayAliases = ''; // 0 = no, 1 = yes
   $pagelistBT->controller->truncateSummaries = '1'; // if a description is used decides whether to shorten it uses a boolean value - 0 = no, 1 = yes
   $pagelistBT->controller->truncateChars = '128'; // amount of characters to shorten the description by.
   $pagelistBT->controller->paginate = ''; // if more pages then the controller->num decide if you would like the results paginated - 0 = no, 1 = yes
   $pagelistBT->render('templates/bs_v_list_5_col'); // Specify a custom template
?>


AUTONAV BLOCK EMBED CODE - FULL PARAMETERS:
(Recommend using these autonav calls with Jordan's autonav custom template - put inside: /blocks/autonav/templates - grab from github here: https://github.com/jordanlev/c5_clean_block_templates/blob/master/au...
<?php 
   $autonavBT = BlockType::getByHandle('autonav'); // grabs the page list block and sets it as the object $autonavBT in this instance
   $autonavBT->controller->displayPages 'below'; // top, above, below, second_level, third_level, custom (Specify the displayPagesCID below)
   $autonavBT->controller->displayPagesCID '62'; // <-- Specify the CID of the page. ( Gets the first level of pages under that section )
   $autonavBT->controller->orderBy 'display_asc';  // display_asc, display_desc, chrono_asc, chrono_desc, alpha_desc 
   $autonavBT->controller->displaySubPages 'relevant';  // none,  relevant, relevant_breadcrumb, all
   $autonavBT->controller->displaySubPageLevels 'custom'; //custom, none
   $autonavBT->controller->displaySubPageLevelsNum '2'; // Specify how deep level 
   $autonavBT->render('templates/sub_nav'); // Specify your template or type "view" to use default
?>


AUTONAV BLOCK EMBED CODE - MAIN NAV EXAMPLE:
<?php
   $autonavBT = BlockType::getByHandle('autonav');
   $autonavBT->controller->orderBy = 'display_asc';
   $autonavBT->controller->displayPages = 'top';
   $autonavBT->render('templates/main_nav');
?>


AUTONAV BLOCK EMBED CODE - BREADCRUMBS EXAMPLE:
<?php
   $autonavBT = BlockType::getByHandle('autonav'); 
   $autonavBT->controller->displayPages = 'top'; 
   $autonavBT->controller->orderBy = 'display_asc'; 
   $autonavBT->controller->displaySubPages = 'relevant_breadcrumb';
   $autonavBT->controller->displaySubPageLevels = 'all';  
   $autonavBT->controller->displayPagesIncludeSelf = 1;
   $autonavBT->render('templates/breadcrumb');
?>


Please add your code - or tips on how to figure the parameters out!

View Replies:
Mnkras replied on at Permalink Reply
Mnkras
Just a note on the search block, since there is nothing dynamic about it, I usually just write out the html for the search because its more efficient.

Mike
cmscss replied on at Permalink Reply
I see - I totally understand what you mean, thanks for that.

How do you guys (as in you developers) figure out the parameters for block embed code?

Is there a php file that spells it out or do you have to understand php?
JohntheFish replied on at Permalink Reply
JohntheFish
In general its the same as the block data, as in the controller and db.xml file (and database).

Anyway, I like what you are doing with this and it will no doubt save lots of people lots of time. Perhaps you could turn it into a howto.
jordanlev replied on at Permalink Reply
jordanlev
Here's a detailed list of all the autonav options:
http://c5blog.jordanlev.com/blog/2012/04/hard-coded-autonav-options...

I've been meaning to post this for a while, finally got around to it -- thanks for the motivation.

ALso, I agree with Mnkras's approach to search boxes. Here's the html I use for those:
<form action="<?php echo View::url('/search'); ?>" method="get">
    <input type="text" name="query" class="" title="Search" />
    <input type="submit" name="submit" value="Search" class="" />
</form>

...that can be tweaked as needed, but the things that it's required to have in order to work are 1) form action and method as listed above, and 2) textbox must have name="query". Everything else can be changed to suit your needs.


-Jordan
mkly replied on at Permalink Reply
mkly
afaik, doing this prevents caching.
jordanlev replied on at Permalink Reply
jordanlev
Darn @mkly, that undermines my whole C5 worldview. Never thought about that (but it makes sense). I'll probably still stick with using them, but definitely good to know for sites that require more optimization.

Thanks for the tip.
mkly replied on at Permalink Reply
mkly
Most of it is probably just the autonav abomination, but indeed blocks can't cache if they aren't blocks.
jbullen replied on at Permalink Reply
jbullen
This is exactly what I need, but I need this for the Related Pages block. Please help!!
jordanlev replied on at Permalink Reply
jordanlev
Do you mean the one from the marketplace? It's a paid addon so you get free tech support -- click the "Support" link in the sidebar of its marketplace page.

The author will be able to tell you if it's possible or not, and how to do so. Do note however that it's not possible to hard-code every block, depending on how complex it is.
RadiantWeb replied on at Permalink Reply
RadiantWeb
why would you hard code blocks anymore when you can code in a Global stack? A global stack would also be much more flexible, would it not?

ChadStrat
jordanlev replied on at Permalink Reply
jordanlev
Global areas/stacks are the bomb, but there are still some situations where hardcoding a block is a better solution -- if you know the block should always be on every page and don't want users to even have the option to change or remove it.

-Jordan
jbullen replied on at Permalink Reply
jbullen
Thanks man
zoinks replied on at Permalink Reply 1 Attachment
• Find the title of the Parent page
• if $title is X, spit out $title with specific style

if ($c->cID > 1) {
               $nh = Loader::helper('navigation');   
               $arrTrail = array_reverse($nh->getTrailToCollection($c));
               $objHomePage = $arrTrail[0]; // Home page object;
               // If we're on a top-level page then our $arrTrail array will only have the home page object
               // so we test to see if its Page object exists
               $objTopPage = is_object($arrTrail[1]) && $arrTrail[1] instanceof Page && !$arrTrail[1]->error ? $arrTrail[1] : $c;
               // If we have a valid top page Page object we retrieve 
               $title = $objTopPage->getCollectionName();
               $url = $nh->getLinkToCollection($objTopPage);
               // ZOINKS check for title match
               if ($title === 'Support') {
               // print parent (if on one of its subpages)
                   echo '<h4 class="sidebarSupport">' . $title . '</h4>' ;
                   } else if ($title === 'Events') {


I used this to spit out the title of the Parent page with color-coded styling above my sidebar autonav.

Here is the CSS that color-coded it based on the various H4 classes in the IF/ELSE statements you see above...
h4.sidebarTheFoundation { text-transform:uppercase; border-bottom:1px solid #eb1c22; width:360px; margin-left:40px; display:block;  }
h4.sidebarTheMuseum { text-transform:uppercase; border-bottom:1px solid #f7941f; width:360px; margin-left:40px; display:block; }
h4.sidebarSupport { text-transform:uppercase; border-bottom:1px solid #ed207b; width:360px; margin-left:40px; display:block; }
h4.sidebarEvents { text-transform:uppercase; border-bottom:1px solid #3bb64c; width:360px; margin-left:40px; display:block; }
h4.sidebarFollowUs { text-transform:uppercase; border-bottom:1px solid #00adef; width:360px; margin-left:40px; display:block; }


And that sidebar autonav below the Parent Page Title worked like this...
<?php
        // AUTO NAV BLOCK 
            $nav = BlockType::getByHandle('autonav');
            $nav->controller->orderBy = 'display_asc';
            $nav->controller->displayPages = 'second_level';
            $nav->controller->displaySubPages = 'relevant';
            $nav->controller->displaySubPageLevels = 'enough_plus1';
            $nav->render('view');
            ?>


...so it only grabbed the 2nd and 3rd tier children (ignoring top tier completely), which I styled in an almost accordion menu type fashion with the following CSS:

#rightSide { width:402px; margin-left:5px; padding:0; float:right; position:relative; height:20px; }
#rightSide ul.nav { list-style-type: none; }
#rightSide ul.nav li { border-bottom:1px solid #ddd; }
#rightSide ul li ul {list-style-type:none; }
#wrapper #content #rightSide ul a:link, 
#wrapper #content #rightSide ul a:visited { color:#000; }
#wrapper #content #rightSide ul a:hover { color: #999; }
#wrapper #content #rightSide ul a:active { color:#000; }
/*second level links */
#rightSide ul.nav li ul {padding-left:0; background-color:#ddd; font-size:13px; list-style-type: square; list-style-position: inside; }
#rightSide ul.nav li ul li { border-bottom:0px; border-top:1px solid #fff; margin:0; padding: 2px 0px 2px 10px; }
#rightSide ul.nav li ul li:hover { background-color: #eee;}
#wrapper #content #rightSide ul li ul a:link, 
#wrapper #content #rightSide ul li ul a:visited { color:#333; }
#wrapper #content #rightSide ul li ul a:hover { color: #000; }


And here's the result in the screenshot attached... an H4 with the appropriate color line underneath and an accordion-ish menu with 2 levels showing only the contents of the Support category (Parent Page). And in the Events section (Parent Page), it says "Events" with a blue underline and the contents of that section. Etc.

It only shows the 3rd tier when the 2nd tier element is clicked on (that is what makes it accordion-ish and this is shown in the screenshot attached... but it is not AJAX, so it is not a true accordion).
ahein624 replied on at Permalink Reply
ahein624
I love the idea of embedding a block. Works great for autonav....however, how do I get it to display results on a search page.

The typical method does not work.