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

Type: Discussion
Status: New
cmscss
View Replies:
cmscss replied on at Permalink Reply
cmscss
OK, was looking for a folder called "designer_content" but realised it was named the same as my DC block.

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?
jordanlev replied on at Permalink Reply
jordanlev
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:
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
cmscss replied on at Permalink Reply
cmscss
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:
<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
jordanlev replied on at Permalink Reply
jordanlev
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:
<h5>
  <a href="<?php echo $field_1_textbox_text; ?>"><?php echo $field_2_textbox_text; ?></a>
</h5>

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.

concrete5 Environment Information

Browser User-Agent String

Hide Post Content

This will replace the post content with the message: "Content has been removed by an Administrator"

Hide Content

Request Refund

You have not specified a license for this support ticket. You must have a valid license assigned to a support ticket to request a refund.