Content Type (JS) ingestion by Cascade Server

birwin's Avatar

birwin

13 Jan, 2015 03:32 PM

Hi everyone, hopefully I'm missing something / someone can help me get going in the right direction.

I have created a content Type (Page) which publishes as a Javascript file. I am using a block and format to create the working Javascript code within this JS File. What I am hoping to accomplish, is be able to link this JS File (composed of block and Format) into one of my templates. This way I can dynamically alter, the blocks, which in-turn updates the Javascript which has some effect on a given page or Pages.

Two examples I'm using this for (and hope to discuss at a later point)

1) "Emergency Response Dialogue" which could be toggled on/off so it appears on every page - this would mean we could publish the one JS file from Cascade, which is already included on all published pages - so in effect every published page will be affected when the new toggled JS file is marked as "on". This saves us from having to re-publish every page

2) "A Brictionary" A collection of blocks with trigger and corresponding replacement word, which can be built easily with either XSLT or Velocity and it does client side content replacement. (There are some drawbacks here I know, but might help some people who have templates in XSLT and want to easily start using the bricks idea.

The linking of the JS file works no problem, when I publish the page with the linked JS content type, everything works, however I'm unable to preview this in Cascade. Is there any way to make it so my linked type works? Here's an example code

XSLT Format (this will be migrated to template later) includes the following code:
<script src="/_Brens Tests/Bricks Example/BrictionaryJS.js" type="text/javascript"></script>
This links to my content-type JS file which generates the working JS. (see attached png)

Any help is appreciated.

This could be under XSLT or Velocity formats, but the way I plan to build the JS files are with Velocity

Thanks all!

  1. 1 Posted by Ryan Griffith on 13 Jan, 2015 07:57 PM

    Ryan Griffith's Avatar

    Hi Brendon,

    You should be able to load up the rendered page as long as:

    • The Output of the page that generates the .js file is the default Output for the Configuration Set. If
    • You are running Cascade Server 7.2+

    If the above are true, you should be able to simply do the following within your Template or Format:

    <script src="/_Brens Tests/Bricks Example/BrictionaryJS?raw" type="text/javascript"></script>
    

    This will tell Cascade Server to render the asset's default output in its "raw" format, meaning it should serve up the raw JavaScript. If you are running Cascade Server 7.12.1 or higher, you can additionally select JS as the output's serialization type so Cascade serves it with the correct text/javascript MIME type.

    Please let me know if you have any questions.

    Thanks!

  2. 2 Posted by birwin on 13 Jan, 2015 08:31 PM

    birwin's Avatar

    Hmm,

    I’m running Cascade 7.12.2

    I have the Serialization Type as JS & File Extension as .js in the configuration set. I modified the XSLT Format to output the following:

    <script src="/_Brens Tests/Bricks Example/BrictionaryJS?raw" type="text/javascript"></script>

    (I tried the name with and without the .js )

    However the script doesn’t appear to run in either of my tests.

    Is there anything else I can troubleshoot?

    Thanks!

    Brendon

  3. 3 Posted by birwin on 13 Jan, 2015 08:33 PM

    birwin's Avatar

    It appears though that the included JS type is now choking because of the system-region tag in the template - even though this publishes ok, my work around:

    <!--#passthrough
    /*
    #passthrough-->
    <system-region name="DEFAULT"> */ // <![CDATA[

    Generated JS HERE

    ]]> /*</system-region>
    <!--#passthrough
    */
    #passthrough-->

    doesn't seem to fly in the JS file itself. I'm wanting the system region to not show up in the file.

    Removing the Pass through, still leaves the system-region tag surrounding the JS.

    Thanks!

  4. 4 Posted by Ryan Griffith on 13 Jan, 2015 08:46 PM

    Ryan Griffith's Avatar

    Hi Brendon,

    Regarding the region tag issue, is this with the JS page or the Format that generates the inline JavaScript?

    For the page that generates the JS file, try setting the Template/Format up like this example, which uses a combination of the protect and skip code sections to generate a non-XML page.

    Also, try adding the [system-asset] pseudo tag to the path, perhaps Cascade is not tracking the link:

    <script src="[system-asset]/_Brens Tests/Bricks Example/BrictionaryJS?raw[/system-asset]" type="text/javascript"></script>
    

    For the inline JS, I'd recommend using protect code sections because they will render the content on preview and publish as opposed to passthrough code sections which only renders the content on publish.

    Please let me know if you have any questions.

    Thanks!

  5. 5 Posted by birwin on 13 Jan, 2015 09:13 PM

    birwin's Avatar

    So I have created a "Page" which content type is the JavaScript, this page is composed of one system-region which houses the block & format used to compose the JavaScript.

    When I use the example:

    <xml><!--#cascade-skip--><unnecessary-tag/><!--#cascade-skip--></xml>

    it effectively turns my JS file into a <xml></xml> (which has none of the JS) so this tells me I do need the <system-region tag>

    My workaround in the template was keep this:

    <!--#passthrough /* #passthrough-->
    <system-region name="DEFAULT"/>
    <!--#passthrough */ #passthrough-->

    which would generate a valid comment in Javascript,

    Taking into account your suggestion with the protect, what I ended up doing was leaving the template as it is above, But I modified my format so the file started with:

    <![CDATA[#protect-top

    instead of: */ //<![CDATA[

    and ended with

    <!--#cascade-skip-->
    #protect-top]]>

    instead of // ]]>
    /*

    which seems to have the desired effect of just leaving the Javascript.

    So, thanks for the help there! I'll try publishing everything and let you know if there are any problems.

    Cheers,

    Bren

  6. 6 Posted by Ryan Griffith on 13 Jan, 2015 09:45 PM

    Ryan Griffith's Avatar

    Hi Brendon,

    My apologies, I should have specified to use the second example under the cascade-skip code section documentation. But, you are correct in that you will still need a region tag. So your Template should look like the following:

    <!--#cascade-skip--><pass-through><system-region name="DEFAULT"/></pass-through>
    

    As you indicated, in your Format you will still need to use protect-top in order to "push" the JavaScript code up above the region and skipped tag within the Template.

    Please let me know if you have any questions.

    Thanks!

  7. Ryan Griffith closed this discussion on 16 Feb, 2015 08:46 PM.

Discussions are closed to public comments.
If you need help with Cascade CMS please start a new discussion.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac

 

26 Aug, 2016 01:19 PM
25 Aug, 2016 03:02 PM
25 Aug, 2016 12:50 PM
24 Aug, 2016 08:43 PM
24 Aug, 2016 07:20 PM
21 Aug, 2016 01:20 PM