AutoNav Custom Template Installation HELP Meh! plz ^_^

Permalink
I am working on my first theme and I wanted to know how to install custom templates for the auto-nav block with the theme as well so the end user won't have to use any ftp programs.

1 Attachment

samuelbarney
 
Mainio replied on at Permalink Reply
Mainio
Just add the block directory inside your package, it will be automatically detected:
/packages/YOUR_PACKAGE_HANDLE/blocks/autonav/templates/your_template.php


Antti / Mainio
samuelbarney replied on at Permalink Reply
samuelbarney
So that's all nothing changes in the controller.php?
Mainio replied on at Permalink Reply
Mainio
Yes, no changes. The c5core will automatically search through every installed package whether they contain custom templates.
samuelbarney replied on at Permalink Reply
samuelbarney
In the block auto nav i have /templates and /img will it create that folder and load the images into it as well or should I be referencing the /themes/themename/images ? I want to somehow keep it together so I can release this as an addon for people who want it even if they don't have the theme. Thanks for all the help btw I feel like a nub making my first theme.
Mainio replied on at Permalink Reply
Mainio
I would use:
/packages/YOUR_PACKAGE_HANDLE/images/


And in the code you can reach it like this:
$pkg = Package::getByHandle('YOUR_PACKAGE_HANDLE');
$imgdir = $pkg->getRelativePath() . '/' . DIRNAME_IMAGES;
samuelbarney replied on at Permalink Reply
samuelbarney
Not completely sure if I follow I want two different things.

1. Have a custom template that can be installed independently of the theme for users who just want the menu so I would need the images to I guess be in the /packages folder for the autonav block.

2. For the theme installation install the custom template that is auto detected but also be able to make sure the images load from the directory inside /blocks this way it's not attached to the theme in any way if that makes sense.
Mainio replied on at Permalink Best Answer Reply
Mainio
I'm not also sure that I'm following you right now.

I assumed you are familiar with the packages concept but if not, here's a good page to read:
http://www.concrete5.org/documentation/how-tos/designers/packaging-...

In your situation, I understood that you want to build a theme that includes a custom template and you want people to install those automatically, right? Probably also want to sell it in the marketplace?

If I'm correct, you should include all in a single package you build:
/packages/your_package_handle/blocks/autonav/templates/your_template.php
/packages/your_package_handle/images/ <-- All the images you want to include in the theme/custom templates within this theme
/packages/your_package_handle/themes/your_theme/ <-- All your theme files
jordanlev replied on at Permalink Reply
jordanlev
I personally handle this in a different way than Mainia is suggesting (and the way I do it should support your ability to move the template out of the theme in the future):

Instead of .../templates/your_template.php, put the template file here:
/packages/YOUR_PACKAGE_HANDLE/blocks/autonav/templates/your_template/view.php


Then, inside that "your_template" directory put any supporting files (view.css, images directory, javascript, whatever). The only annoying part of this is that C5 doesn't provide a way (that I could tell) to consistently give you the directory that the template exists in. So I put this at the top of my template files:
$imgPath = DIR_REL . '/packages/YOUR_PACKAGE_HANDLE/blocks/autonav/templates/your_template/images';

Then all the img src's would be:
<img src="<?php echo $imgPath; ?>/something.jpg" />


...So when you move it outside of this package you have to remember to change that $imgPath thing at the top of the file, but other than that everything is clean and stays in one directory.
jordanlev replied on at Permalink Reply
jordanlev
By the way, I recently filed a bug report about this issue... please "upvote" it by going here and clicking the green "plus sign" button:
http://www.concrete5.org/developers/bugs/5-5-2/blockviewtemplateget...
samuelbarney replied on at Permalink Reply
samuelbarney
thnx Jordan & Mainio between the both of you I think I got what was needed but I'll test it on a fresh install