Custom Template for Form Output of Page Type
PermalinkI 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

The code that picks this up is in /concrete/src/Entity/Block/BlockType/BlockType.php getBlockTypeComposerTemplates()
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
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).
I agree, this would really help clarify that it is not applied like a standard template.
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
Just to clarify, are you using the code you shared as the block view custom template or the block Composer form custom template.
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
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.
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
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...