How do you add a custom template to render the output?
Permalink Browser Info Environment
Hi There,
I need some markup to render the output of a Designer Content custom block but can't figure out how to do it - is it possible?
Any help would be much appreciated.
Cheers
Ben
I need some markup to render the output of a Designer Content custom block but can't figure out how to do it - is it possible?
Any help would be much appreciated.
Cheers
Ben
Type: | Discussion |
---|---|
Status: | New |
Yes, editing the view.php file in your block's directory is the way to do it. You can locate this directory based on the handle that you entered when creating the block. For example, if you gave it a block handle of "my_custom_block", then you can find the block directory here:
You can either modify the view.php file there directly if you want to override the default view, or as you point out you can also create custom templates for it by creating a new directory in there called "templates" and copying the view.php file into that templates directory and renaming it to something else.
Let me know if you have any other questions about this or run into problems.
-Jordan
YOURSITE/blocks/my_custom_block/
You can either modify the view.php file there directly if you want to override the default view, or as you point out you can also create custom templates for it by creating a new directory in there called "templates" and copying the view.php file into that templates directory and renaming it to something else.
Let me know if you have any other questions about this or run into problems.
-Jordan
Mate, thanks for writing this add-on - it's such an awesome addition to the c5 community!
Just a quick question:
I have a link field that I would like to wrap several items such as the headline and images but my limited knowledge of PHP means I can't get it working.
This is the output for the headline:
And this is the link output:
What would the best way to combine them so link wraps the headline in PHP? I've tried various incarnations but I think the if statements are getting in the way maybe as it doesn't work.
Any help would be much appreciated.
Cheers
Ben
Just a quick question:
I have a link field that I would like to wrap several items such as the headline and images but my limited knowledge of PHP means I can't get it working.
This is the output for the headline:
<h5> <?php if (!empty($field_5_textbox_text)): ?> <?php echo htmlspecialchars($field_5_textbox_text, ENT_QUOTES, APP_CHARSET); ?> <?php endif; ?> </h5>
And this is the link output:
<p> <?php if (!empty($field_6_image)): ?> <?php if (!empty($field_6_image_externalLink)) { ?><a href="<?php echo $field_6_image_externalLink; ?>"><?php } ?> <img src="<?php echo $field_6_image->src; ?>" width="<?php echo $field_6_image->width; ?>" height="<?php echo $field_6_image->height; ?>" alt="<?php echo $field_6_image_altText; ?>" /> <?php if (!empty($field_6_image_externalLink)) { ?></a><?php } ?> <?php endif; ?> </p>
What would the best way to combine them so link wraps the headline in PHP? I've tried various incarnations but I think the if statements are getting in the way maybe as it doesn't work.
Any help would be much appreciated.
Cheers
Ben
Is this a link to an external page (one that's not in your site)? If so, I'd just make two textbox fields, then output them in the view.php file like this:
Note that this assumes the first textbox field (field_1_textbox_text) is for the link URL, and the second (field_2_textbox_text) is for the heading text. You'll probably need to change those numbers depending on the output of your particular block.
If, on the other hand, this is a link to another page within your site, just use the "Page Link" field instead.
Note that this assumes the first textbox field (field_1_textbox_text) is for the link URL, and the second (field_2_textbox_text) is for the heading text. You'll probably need to change those numbers depending on the output of your particular block.
If, on the other hand, this is a link to another page within your site, just use the "Page Link" field instead.
Is editing the view.php file the best way to style the output is can you create a templates folder and add a custom template to it?