Main Content

Magnolia Community Forums: Get help with Magnolia: cmsfn with angular


  • mariop96
    mariop96
    Full name: mario pacheco
    Posts: 6
    Last post: Jul 31, 2017 12:25:44 AM
    Registered on: Apr 28, 2017
    cmsfn with angular
    #1 by mariop96 on Jul 24, 2017 9:01:51 PM

    greedings to everyone, i'm trying to pass a variable to angularjs from cmsfn, someone already did it?


    <div ng-controller="someController">
    [#assign currentNode = cmsfn.asJCRNode(content)]
    [#assign rootPageNode = cmsfn.root(currentNode, "mgnl:page")!]
    <div style="display: none">{{myVar='${rootPageNode}'}}</div> </div>

    but where i try to use myVar in angular, it's empty.
    Any suggestion?
    thank you in advance

  • cmeier
    cmeier
    Full name: Christoph Meier
    Posts: 210
    Last post: Jul 25, 2017 6:09:04 PM
    Re: cmsfn with angular
    #2 by cmeier on Jul 24, 2017 9:52:01 PM

    Hi Mario

    You should explain a bit more in detail what exactly you are trying to do.

    From what file have you pasted a snippet?
    Is it a template, If yes, what template ... page or component? Or are you working with "processed resources"?
    What is the context of the content object which you are using within your code? Is it a node of a page, of a component or what ist it?

    cheers,
    Christoph

  • mariop96
    mariop96
    Full name: mario pacheco
    Posts: 6
    Last post: Jul 31, 2017 12:25:44 AM
    Registered on: Apr 28, 2017
    Re: cmsfn with angular
    #3 by mariop96 on Jul 25, 2017 11:41:32 AM

    Hi Christoph, it's a page template, i'm trying to get a page name to angularjs, to do a request and bring the page properties. if know other way to do what i want, please feel free to say.

    thanks

  • cmeier
    cmeier
    Full name: Christoph Meier
    Posts: 210
    Last post: Jul 25, 2017 6:09:04 PM
    Re: cmsfn with angular
    #4 by cmeier on Jul 25, 2017 6:09:04 PM

    Hi Mario

    My first hint is: Understand the freemarker ${myObject} expression :-)
    It is similar to the #toString method in Java.
    Simply said freemarker applies #toString to the object (myObject).

    When you pass the typical content object (which is of type info.magnolia.jcr.util.ContentMap), freemarker will render the name of the node.
    When you pass a javax.jcr.Node - which you get with cmsfn.asJCRNode(content)
    freemarker renders the path of the node.

    However, I think you want to pass to your angular snippet rather a property of your page node, e.g. the title.
    You can do something like this:


    [#assign title=content.title!content.@path]
    <div ng-controller="someController">
    <div style="display: none">{{myVar='${title}'}}</div>
    </div>


    If your prefer the title of the rootNode:

    [#assign rootPageNode = cmsfn.root(content, "mgnl:page")!]
    [#if rootPageNode??]
    [#assign title=rootPageNode.title!rootPageNode.@path]
    [#else]
    [#assign title=content.title!content.@path]
    [/#if]
    [#-- Note that rootPageNode could be null, if you area öready on a "root level page" --]

    <div ng-controller="someController">
    <div style="display: none">{{myVar='${title}'}}</div>
    </div>



    Some links for you:
    - http://freemarker.org/docs/ref_builtins_string.html
    - https://documentation.magnolia-cms.com/display/DOCS/Templating+function+arguments+and+return+types

    I hope this helps :-)
    Cheers,
    Christoph

  • tgregovsky
    tgregovsky
    Full name: Tomáš Gregovský
    Posts: 6
    Last post: Jul 31, 2017 9:12:34 AM
    Re: cmsfn with angular
    #5 by tgregovsky on Jul 26, 2017 1:22:39 PM

    hi Mario, also looking at your code then this should do what you want:


    <div ng-controller="someController">
    [#assign rootPageNode = cmsfn.root(content, "mgnl:page")!content ]
    <div style="display: none">{{myVar='${rootPageNode.@name}'}}</div>
    </div>


    just remember if this code is execute on root page (root node), then cmsfn.root returns null, so then you have to use 'content' instead
    and .@name (same as .@id, .@depth and .@path) is property which every node has. other that that you can use .title or anything your node related but then you have to check first if with ?has_content

    Tomas

  • mariop96
    mariop96
    Full name: mario pacheco
    Posts: 6
    Last post: Jul 31, 2017 12:25:44 AM
    Registered on: Apr 28, 2017
    Re: cmsfn with angular
    #6 by mariop96 on Jul 27, 2017 5:18:07 PM

    thanks you guys,

    didn´t work with 'if rootPageNode??' but it works with 'if rootPageNode?has_content'. I have another question, when I'm creating a new page, i want to use properties from parent node, its possible get properties from new page's parent?

    thank you,
    Mário

  • tgregovsky
    tgregovsky
    Full name: Tomáš Gregovský
    Posts: 6
    Last post: Jul 31, 2017 9:12:34 AM
    Re: cmsfn with angular
    #7 by tgregovsky on Jul 28, 2017 8:28:49 PM

    sure, once you have your
    [#assign rootPageNode = cmsfn.root(content, "mgnl:page")!content ]
    you can easily do ${rootPageNode.<any-property>}, and of course you can also go to sub nodes, such as areas... ${rootPageNode.main.<component>.<any-property>} of course with all proper ?has_content checks. To be sure what you want to use, check where this property is in "jcr browser" > "websites"

  • mariop96
    mariop96
    Full name: mario pacheco
    Posts: 6
    Last post: Jul 31, 2017 12:25:44 AM
    Registered on: Apr 28, 2017
    Re: cmsfn with angular
    #8 by mariop96 on Jul 31, 2017 12:25:44 AM

    Tomas, i'm talking about when i'm setting properties of new page, in the dialog, it is possible get information about the ancestor node, here in the properties dialog?

    thanks

    Mário

  • tgregovsky
    tgregovsky
    Full name: Tomáš Gregovský
    Posts: 6
    Last post: Jul 31, 2017 9:12:34 AM
    Re: cmsfn with angular
    #9 by tgregovsky on Jul 31, 2017 9:12:34 AM

    if you will create you custom field class then yes.

You don't have the permission to post on this thread

Sign in

To login on this forum, you can use your Magnolia Forge, Support or Partner account, or, below, your Google, Yahoo! or OpenID account. If you have trouble logging in, or any other sort of issue, please let us know in the Meta forum, on the user-list, or simply by email at forum-admin at magnolia-cms dot com.

* Required

... or sign in with:

  • icon http://{your-openid-url}
  • icon
  • icon https://me.yahoo.com/