Skip to content
This repository has been archived by the owner on Aug 22, 2023. It is now read-only.

JSON is not loading #13

Closed
gpunx opened this issue Jun 6, 2013 · 7 comments
Closed

JSON is not loading #13

gpunx opened this issue Jun 6, 2013 · 7 comments

Comments

@gpunx
Copy link

gpunx commented Jun 6, 2013

I have created an index.json file. This sits in the same directory as index.swig. When trying to load a property defined in index.json in index.swig, nothing happens. I have created a simple property called heading in my index.json file and am trying to load it by using:

{{ heading }}

in my swig file. Below is my swig config in Gruntfile.js and the index.json file i am loading.

swig config:

swig: {
            development: {
                init: {
                    root: "struct/swig/",
                    allowErrors: true,
                    autoescape: true
                },
                dest: "www/",
                cwd: "struct/swig/",
                src: ['**/*.swig'],
                generateSitemap: false,
                generateRobotstxt: true,   
                siteUrl: 'http://mydomain.net/',
                production: false,
                fb_appid: '1349v',
                ga_account_id: 'UA-xxxxxxxx-1',
                robots_directive: 'Disallow /',
                sitemap_priorities: {
                    '_DEFAULT_': '0.5',
                    'index': '0.8',
                    'subpage': '0.7'
                }
            }
        }

index.json

{
    "heading": "The Home Page"
}

The page renders as expected. The only thing it is missing is the JSON variable. I am not sure if I am missing a step or if there is a bug. I am fairly new to grunt and swig. Thanks for any help/direction/assistance/slap-upside-the-head that can be given.

@thisispete
Copy link

having the same issue.

its's looking for the 'tplVars' at config.data.root +file + '.json'
however root is now at config.data.init.root... and can be an array of files not just one string..

seems to work if you declare a variable in the grunt file for 'root' at the same level as 'dest' 'init' 'src' etc. as long as you're only using one root directory.. but for more complicated inheritance structures it could be tricky.

@thisispete
Copy link

ie

swig: {
            development: {
                init: {
                    root: "struct/swig/",
                    allowErrors: true,
                    autoescape: true
                },
                dest: "www/",
                root: "struct/swig/",
                cwd: "struct/swig/",
                src: ['**/*.swig'],
                generateSitemap: false,
                generateRobotstxt: true,   
                siteUrl: 'http://mydomain.net/',
                production: false,
                fb_appid: '1349v',
                ga_account_id: 'UA-xxxxxxxx-1',
                robots_directive: 'Disallow /',
                sitemap_priorities: {
                    '_DEFAULT_': '0.5',
                    'index': '0.8',
                    'subpage': '0.7'
                }
            }
        }

@gpunx
Copy link
Author

gpunx commented Jun 7, 2013

awesome! thanks, pete! i had caught the same thing you did yesterday. thought i had tried it. the only thing i can think of is that i didn't restart grunt. ...and that would be a big ol' DOH! all is working now. thanks, again!

@rtgibbons
Copy link
Owner

Thanks for the details. We had refactor how the settings are stored. It looks like the right fix off hand is to just update the code to grab the root from the init object. I'm hoping to have some time this weekend to work on this a bit.

@thisispete
Copy link

For what its worth - It might be better to use the cwd to make the path instead of the init root. Since swig allows for an array of roots. (So you can have a templates folder or whatever in a separate dir)

@nickpack
Copy link
Collaborator

nickpack commented Jun 8, 2013

Ah I can see exactly where this is an issue, and that it isnt covered by our test suite. I'll implement a quick fix shortly to restore the existing behavior, but I agree completely with @thisispete that it should handle multiple roots - though this could get tricky with multiple files with the same name ;)

nickpack added a commit to nickpack/grunt-swig that referenced this issue Jun 8, 2013
@nickpack
Copy link
Collaborator

nickpack commented Jun 8, 2013

This has been fixed, and is released to npm as version 0.0.12

@nickpack nickpack closed this as completed Jun 8, 2013
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants