Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

[Snowman] How do I implement the macro in Snowman 2? What about prerender and postrender

I love Snowman because I'm good with jQuery but the missing macros really bother me....

How can I display one passage within another? I have some scripts that I reuse often but organizationally don't really belong in Story Javascript.

Additionally, has anyone got any ideas about implementing prerender and postrender events in Snowman?

Comments

  • edited January 2016
    ...but the missing macros...
    Snowman does not have macros as such, instead you create custom Javascript functions which you call using Underscore templating (<% .. %>, <%= .. %>, etc)
    note: The following example includes very basic namespace and function definitions for simplicity sake.

    a. Define your custom functions using a namespace.
    if (!window.GE){
    	window.GE = {
    		debug: function debug(message) {
    			console.log(message);
    		}
    	};
    }
    
    b. Call the function within your passage
    <% GE.debug('debug called') %>
    

    How can I display one passage within another?
    You use the story.render function to do this
    <%= story.render("Other Passage") %>
    

    implementing prerender and postrender events
    The story.show function is called when a the story navigates between passages, it includes a number of events which can be used to run custom code.

    a. The showpassage event, which occurs before a passage is shown. You can use code like the following in your Story Javascript area:
    jQuery(window).on('showpassage', function(){console.log('showpassage event');});
    
    b. The showpassage:after event, similar to the A except it occurs after a passage has been shown. You can use code like the following in your Story Javascript area:
    jQuery(window).on('showpassage:after', function(){console.log('showpassage:after event');});
    
    C. The passage _readyFunc helper function can be used within a passage to setup a customer function to be called on only that passage's showpassage:after event. You use the special $ method:
    <% $(function(){console.log('_readyFunc called');}) %>
    
  • Thank you for your in-depth reply! Many things were made clearer ;)
Sign In or Register to comment.