-
Notifications
You must be signed in to change notification settings - Fork 107
Default content #24
Comments
Hi Jamie, Any property you define in Is this what you're looking for? |
That's exactly what I'm after, thanks. Just for the record, when I run On a similar subject, how would I go about creating functions on the view for example a |
What's the version of Punch you are using? (run On a similar subject, how would I go about creating functions on the view
You can implement a custom helper to generate the link tags. There you can |
Apologies, I wasn't on the latest release, that's great. Thanks, helpers look like the solution to custom blocks. Where would I put these for them to get picked up? ...sorry for the dumb questions but the helpers page in the Wiki is currently blank. |
One last question, after upgrading my public files are not getting served e.g. |
Keep those questions coming. That'll help me to figure out what needs You can place the custom helpers in anywhere in the project (I would On Fri, Sep 7, 2012 at 5:57 PM, Jamie Hill notifications@github.com wrote:
|
Are they placed in On Fri, Sep 7, 2012 at 6:12 PM, Jamie Hill notifications@github.com wrote:
|
Excellent, that clears that up. I was previously just putting my assets, images etc. in the public directory (like in Rails) and they were getting found, I've moved them to the templates dir and all is fine. One thing I would say is that having to have all the images etc. in the template directory means that you are effectively doubling the size of your project on disk as they all just get copied to the public directory anyway. |
Public directory (or the output directory) is used only to preview the site during the development or to upload the generated site to a remote server. So if you are not actively working on a site, you can simply delete its Also, having static assets in templates would make it easy to switch the design of a site, by just replacing the templates directory. |
I see the reasoning now, so you could basically ignore the public directory entirely in a git project and just run |
Sorry to be a pain... on the subject of setting a What would be nicer is being able to just insert a View {
"nav": [
{ "label": "Home", "class": "home", "href": "/" },
{ "label": "About Us", "class": "about-us", "href": "/about", "current": true } // 'current' inserted dynamically
]
} Template <nav>
<ul>
{{#nav}}
<li class="n-{{class}}{{#current}}current{{/current}}"><a href="#">{{label}}</a>
{{/nav}}
</ul>
</nav> I can't see a way of doing this with the current setup, am I missing something? |
Did you check the Current Page Helper plugin? https://github.com/laktek/punch-current-page-helper Follows a very similar syntax to what you suggest, only you have to pass the URL between the section tags {{#current}}..{{/current}}. |
Ah, I didn't see that one, thanks. What's the best way to install plugins other than just copying the code into a helper? |
Every Plugin's README provides the necessary steps to install. Basically, On Sun, Nov 18, 2012 at 11:53 PM, Jamie Hill notifications@github.comwrote:
|
Great, thanks. |
Slight problem with that approach, what if you already have classes on your tag and therefore need a space before it? |
Yep..you will need to keep a space in between. On Mon, Nov 19, 2012 at 12:05 AM, Jamie Hill notifications@github.comwrote:
|
But then, you will end up with a space even when not using the |
Hmm..true. I'll see if I could improve it in a way so there won't be a need On Mon, Nov 19, 2012 at 12:09 AM, Jamie Hill notifications@github.comwrote:
|
I still think the best option is to allow hooking into the content object. |
@thelucid and @laktek I'm not much of a HTML + CSS person, but sometimes I leave spaces in my class definitions for this reason (either with punch or other frameworks like Django) What is the downside of leaving spaces? Is it aesthetic or can it cause parse problems? |
@jtrain Both, I like to keep markup as clean as possible and have experienced validation issues in the past. @laktek How do you feel about some kind of system whereby you could hook into the content for a request e.g. module.exports = {
after: function(request, content) {
content['some_key'] = 'some value';
}
}; Not sure about the method name |
@thelucid This is part of what helpers do. It extends the content (for more straightforward example check, Third Party Snippets Helper ). However, in this case of adding something like a current flag to a link within a list, Punch has to be aware of the structure of the content and modify it. That's not practical because different users will choose different structures for their content. |
I'm not saying that Punch should implement the 'current' functionality itself, just a generic hook that allows users like myself to manipulate the content before it gets handed to the template. The callback that manipulated the content could be given access to the request as per my example. I see uses other than the 'current' flag. |
Helpers do have access to the request. However, it's not aware of the rest of the content model. Have to see whether it can be accommodated with helpers itself, or should we need a new type of a hook. If you're interested to dig deeper on this idea, please go ahead. |
I'm closing this thread. It's better to move any further discussions about exposing content to helpers in to a separate issue. |
Hi,
Is there currently any way of implementing default/site-wide content? I'm thinking a
defaults.json
orsite.json
file where the contents for each page get deep merged into it to accommodate common site content.On second thoughts, it wouldn't necessarily even need to be merged, it could just add a
site
key to the json that is made available to the template.Is there currently a way to achieve this before I go ahead and look adding it?
The text was updated successfully, but these errors were encountered: