Trouble creating a custom block template - I'm using the Concrete5 beginners guide e-book as a guide
Permalink
Hi There,
I'm trying to create a custom template for the pageList block but keep getting a variety of errors.
I've read a few guides in addition to the book:
http://www.concrete5.org/documentation/how-tos/designers/custom-blo...
http://www.concrete5.org/community/forums/usage/how-to-make-a-custo...
http://www.concrete5.org/community/forums/installation/page-list-bl...
But I'm now really confused as the links above each say something different - which is different again from what the book says to do.
The book says to do the following:
1.
Copy "concrete/blocks/page_list/view.php" to "blocks/page_list/templates/ - and create directories and rename view.php to news.php.
2. Replace the php with the php from the book (I copied and pasted).
3. Go to the news listing page an activate the custom template.
After following these steps I'm seeing the following error:
"Parse error: syntax error, unexpected $end in /Path/to/blocks/page_list/templates/news.php on line 20"
The big difference between the book and myself is that I'm using my own template - and am just using a right sidebar page type to list the news items.
Does a template need anything special in order to list pages using a custom block template? I've been looking at a test site with the demo content installed but can't find anything different (the blog home page just uses a right sidebar template as well).
Any help would be much appreciated - I'm new to c5 and php so sorry if this is easy.
Cheers
Ben
I'm trying to create a custom template for the pageList block but keep getting a variety of errors.
I've read a few guides in addition to the book:
http://www.concrete5.org/documentation/how-tos/designers/custom-blo...
http://www.concrete5.org/community/forums/usage/how-to-make-a-custo...
http://www.concrete5.org/community/forums/installation/page-list-bl...
But I'm now really confused as the links above each say something different - which is different again from what the book says to do.
The book says to do the following:
1.
Copy "concrete/blocks/page_list/view.php" to "blocks/page_list/templates/ - and create directories and rename view.php to news.php.
2. Replace the php with the php from the book (I copied and pasted).
3. Go to the news listing page an activate the custom template.
After following these steps I'm seeing the following error:
"Parse error: syntax error, unexpected $end in /Path/to/blocks/page_list/templates/news.php on line 20"
The big difference between the book and myself is that I'm using my own template - and am just using a right sidebar page type to list the news items.
Does a template need anything special in order to list pages using a custom block template? I've been looking at a test site with the demo content installed but can't find anything different (the blog home page just uses a right sidebar template as well).
Any help would be much appreciated - I'm new to c5 and php so sorry if this is easy.
Cheers
Ben
Have reinstalled using default content - guess I'll do that from now on but what is it about the default content that makes it work?
There must be more to it than the content right?
There must be more to it than the content right?
I'm not sure what those guides are all about, but here's how you create a custom template for the page_list (let's say for example you want to call this template "Recipe List"):
1) Create new directory (if it doesn't already exist): YOURSITE/blocks/page_list/templates/
2) Copy YOURSITE/concrete/blocks/page_list/view.php to the YOURSITE/blocks/page_list/templates/ directory from step 1.
3) Rename the new copy of that file to "recipe_list.php"
4) Edit that file and modify it to your liking.
That's it -- I think the guide may have zany php code that should not be pasted in there.
As for the blog_index.php issue, that is specific to the way that template works -- it only works when listing pages of type "blog_entry" (those page types have special code in their controller to respond to that getCommentCountString() function).
Hope that helps.
-Jordan
1) Create new directory (if it doesn't already exist): YOURSITE/blocks/page_list/templates/
2) Copy YOURSITE/concrete/blocks/page_list/view.php to the YOURSITE/blocks/page_list/templates/ directory from step 1.
3) Rename the new copy of that file to "recipe_list.php"
4) Edit that file and modify it to your liking.
That's it -- I think the guide may have zany php code that should not be pasted in there.
As for the blog_index.php issue, that is specific to the way that template works -- it only works when listing pages of type "blog_entry" (those page types have special code in their controller to respond to that getCommentCountString() function).
Hope that helps.
-Jordan
OK mate, will look at this tonight.
Sorry for multiple posts on the same subject - I only started with c5 a week ago and just can't seem to make this aspect to c5 work.
Sorry for multiple posts on the same subject - I only started with c5 a week ago and just can't seem to make this aspect to c5 work.
No worries. Here's a cleaned up version of the built-in page list template which might be easier to customize:
<?php defined('C5_EXECUTE') or die("Access Denied."); $textHelper = Loader::helper("text"); ?> <div class="ccm-page-list"> <?php foreach ($cArray as $cobj): $title = $cobj->getCollectionName(); $link = $nh->getLinkToCollection($cobj); $target = $cobj->getAttribute('nav_target'); if (!empty($target)) { $target = 'target="' . $target . '"'; } $summary = $cobj->getCollectionDescription(); if ($controller->truncateSummaries) { $summary = $textHelper->shorten($summary, $controller->truncateChars);
Viewing 15 lines of 41 lines. View entire code block.
Mate you're on fire! I can't tell you how much appreciate your help - if you have a PayPal account, let me me buy you a beer.
Thanks again - will try that now.
Cheers
Ben
Thanks again - will try that now.
Cheers
Ben
Does the PHP code posted require a content area on the entry page called $summary maybe?
I seem to get an error:
"Fatal error: Call to a member function shorten() on a non-object in /path/to/site/blocks/page_list/templates/recipe_list.php on line 14"
Line 14 is:
I seem to get an error:
"Fatal error: Call to a member function shorten() on a non-object in /path/to/site/blocks/page_list/templates/recipe_list.php on line 14"
Line 14 is:
$summary = $textHelper->shorten($summary, $controller->truncateChars);
Did you copy and paste the entirety of my code above, or just pieces of it? The 3rd line of my code ($textHelper = Loader::helper('text');) is what loads the object. If you leave that out, the call to shorten() on line 14 won't work.
If you left that in there but it's still not working then something very strange is going on with your system (perhaps not every file got copied properly when you installed or moved to a different server or something? or were you mucking around with the files in the /concrete/ directory by any chance?)
If you left that in there but it's still not working then something very strange is going on with your system (perhaps not every file got copied properly when you installed or moved to a different server or something? or were you mucking around with the files in the /concrete/ directory by any chance?)
I haven't touched anything inside if I just used your code (markup and all) I got the same error.
I think to be safe, I should perform a clean install.
Cheers
Ben
I think to be safe, I should perform a clean install.
Cheers
Ben
"Fatal error: Call to undefined method Controller::getCommentCountString() in /path/to/blocks/page_list/templates/news.php on line 17"