gulp-file-include
gulp-file-include copied to clipboard
Can you carry variables(JSON Objects) deeper then just 1 layer somehow?
I've got this setup:
|> meta.html
|> script.html
|> libs.html
[home/index/aboutme/etc].html > index_wo_content.html |> content.html
|> banner.html
|> links.html
|> footer.html
|> etc.
Is it in any way shape or form possible to declare a JSON Object i can carry from the main file to the meta.html? I want to expand this system to a degree so i can configure each pages special attributes easily for SEO optimizing. Here are my Code Snippets i use:
main.html
@@include('./index_wo_content.html', {
"metadata": {"keywords": "a long string of keywords"},
"nav":"projekte",
"badbrowser":false,
"modal": false
})
index_wo_content.html
@@if (typeof(metadata)!='undefined') {
@@include('./meta/meta.html')
}
meta.html
@@if (typeof(metadata)!=='undefined'){
<meta name="keywords" content="@@metadata"/>
}
@@if (typeof(metadata)==='undefined'){
<meta name="keywords" content="Long list of default keywords....."/>
}
Fixed it but its really not pretty imo... index_wo_content.html
@@if (typeof(context.metadata)!='undefined') {
@@include('./meta/meta.html', {"metadata": {"keywords":"@@metadata.keywords"}})
}
@@if (typeof(context.metadata)==='undefined') {
@@include('./meta/meta.html')
}
meta.html
@@if (typeof(context.metadata)!=='undefined'){
<meta name="keywords" content="@@metadata.keywords"/>
}
@@if (typeof(context.metadata)==='undefined'){
<meta name="keywords" content="Long list of keywords..."/>
}
Not if you've tried this yet, but yes, sub objects work! I just double checked to make sure with this:
index.html
@include('./_sample-template.html', {
"root":"./",
"foo":"Bar",
"data":"sample-collection",
"test": {
"someText": "hello world"
}
})
_sample-template.html
<p>@@test.someText</p>