Custom Template for Form Output of Page Type

Permalink
Hello all,

I am having a hard time getting a custom template for the File block to show up in the Compose Form area of a my Page Type (see image attachment). I see there is an option to use a custom template in the modal, but I don't know where the actual template file is supposed to live in the file structure. I have used custom templates for blocks by putting them in directory like this:

application/blocks/file/templates/my_custom_name/view.php

While that works for applying a template to a block element with the Design & Custom Template menu, it doesn't work with the Compose Form menu. Can someone please let me know where I should put the template file to get it to show up?

Thanks,
Craig

1 Attachment

vergedesign
View Replies: View Best Answer
jero replied on at Permalink Reply
jero
You would need to drop an edit.php, add.php and composer.php into application/blocks/file.
vergedesign replied on at Permalink Reply
vergedesign
Thank you for the reply jero, but that did not seem to make a difference. The Custom Template select menu in the Compose Form block still has no options. I tried adding the 3 files you suggested to application/blocks/file as well application/blocks/file/templates/my_custom_folder.
jero replied on at Permalink Reply
jero
You need to create a folder called "composer" in application/blocks/your_block and then drop your custom php file(s) into that folder.

The code that picks this up is in /concrete/src/Entity/Block/BlockType/BlockType.php getBlockTypeComposerTemplates()
vergedesign replied on at Permalink Reply
vergedesign
Ah, thank you for that jero! This got me closer.

Now when I create the directory path application/blocks/file/composer/my_template_name/view.php, I get the my_template_name view file to come up in the Compose Form select menu. However, when I apply it to the File attribute in the menu, and try to create a new page, it throws a 500 error that seems to be connected to jQuery. I have tried adding all of the other files from the concrete/blocks/file directory to my custom directory mentioned above, but it doesn't solve the issue.

I really appreciate your time, and I feel like I am close. Any other suggestions?

Thanks,
Craig
jero replied on at Permalink Reply
jero
If you check out the code, you'll see that it doesn't allow folders within the composer folder, so instead of composer/my_template/view.php you have to use composer/my_template.php
MrKDilkington replied on at Permalink Reply 1 Attachment
MrKDilkington
@jero

Thanks for looking into this. Your answer is correct.

Also, I think that the label of "Custom Template" could be updated to better describe what is being selected. Maybe something like "Composer Custom Template" (see attached file).
vergedesign replied on at Permalink Reply
vergedesign
@MrKDilkington

I agree, this would really help clarify that it is not applied like a standard template.
vergedesign replied on at Permalink Reply
vergedesign
Thanks jero and MrKD. I really appreciate the time you are taking to help out.

While jero's suggestions do allow me to select my custom File template in the Compose Form select menu, it doesn't actually work when composing a new page.

What I am trying to do is create a custom File Block Composer Template, so rather than having the button name pull and display the file name, it is static text. Seems simple, but when I apply this template and try to create a new page, this block always show the EMPTY FILE BLOCK div, and never gives me a chance to add a link to the file.

Below is my edited code. I only changed one line: I took out "<?php echo stripslashes($controller->getLinkText()) ?>" from the <a> tag, and replaced it with "Download PDF File".

<?php  defined('C5_EXECUTE') or die("Access Denied.");
$f = $controller->getFileObject();
$fp = new Permissions($f);
if ($f && $fp->canViewFile()) {
    $c = Page::getCurrentPage();
    if ($c instanceof Page) {
        $cID = $c->getCollectionID();
    }
    ?>
   <div class="ccm-block-file">
      <a href="<?php echo $forceDownload ? $f->getForceDownloadURL() : $f->getDownloadURL();
    ?>">Download PDF File</a>
   </div>
<?php
}


This shouldn't cause any issues with the conditional that displays my edited block. Just can't seem to get it to work.

Craig
MrKDilkington replied on at Permalink Reply
MrKDilkington
@vergedesign

Just to clarify, are you using the code you shared as the block view custom template or the block Composer form custom template.
vergedesign replied on at Permalink Reply
vergedesign
MrKDilkington,

I originally used it as a block view custom template, applied to the Output of my Page Type, which works fine, when applied with the Design and Custom Template menu. Then I figured it would be a more elegant solution to use it in the Compose Form select menu (as in the attachment you sent). I am editing the same view.php file... the one from concrete/blocks/file/view.php as my base file. I made my one line edit, and put it in applications/blocks/file/composer/my_template_name.php

Is this the wrong file to begin with, or practice? I have never tried this before, so I am using a process similar to creating custom block templates.

Craig
jero replied on at Permalink Best Answer Reply
jero
The composer template and view templates are completely different things. One is an output for the block when displaying the page. The other is basically a form that allows you to set the block contents up. You would not want to show a form when the page is viewed, and the output of the block would be useless when you're trying to edit the contents.

What exactly are you trying to achieve here? Do you simply want to set a custom view template for the block? If so, then you should be able to do that by editing the page type output and setting the template there just as you would when editing a regular page. Head over to /index.php/dashboard/pages/types and click "Output" on the appropriate page type and follow your nose from there.
vergedesign replied on at Permalink Reply
vergedesign
@jero

Yeah, I clearly don't know enough about the c5 file structure to work with a Composer element. I saw that Compose Form was allowing for a Custom Template, and figured it was the same process as adding a custom block template. Now I see that it isn't, and I apologize for the wasted effort on your part.

I thought my first message spelled out pretty clearly what I was trying to do, but my ignorance regarding the differences between Custom Templates and Composer Templates may have muddied the water a bit.

I actually already have a block template working in the Output file of my Page Type -> Page Template. It just seemed like a less clean solution. I'll stick with it.

Thanks again to you, and to MrKD for the info.

Craig
MrKDilkington replied on at Permalink Reply
MrKDilkington
@vergedesign

To better assist others in finding solutions to questions, can you mark jero's reply as the answer, please.

https://www.concrete5.org/community/forums/customizing_c5/custom-tem...