Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Matt Taylor 873 posts 2086 karma points
    May 29, 2013 @ 14:18
    Matt Taylor
    0

    Setting CurrentContent?

    I'm using alternate templates to render the content other nodes by passing in the node ID.

    string id = Request.QueryString["id"];
    int nodeID;
    if (int.TryParse(id, out nodeID))
    {
        DocumentTypes.NewsArticle newsArticle = ContentHelper.GetByNodeId<DocumentTypes.NewsArticle>(nodeID);
        this.CurrentContent = newsArticle;
    }

    I thought I could set CurrentContent and use it in the template like any other but CurrentContent cannot be set.

    Is there some other intelligent way to to do this?

    Regards,

    Matt

  • Stephen 47 posts 270 karma points
    May 29, 2013 @ 14:26
    Stephen
    0

    Are you trying to render another news article on the page if a different id is passed in? Can you use RenderTemplate instead?

    Stephen

  • Sasa Popovic 77 posts 367 karma points
    May 29, 2013 @ 14:27
    Sasa Popovic
    100

    Hey Matt,

    Why wouldn't you just make a protected property in your alternate template's code behind class, initialize it with the retrieved NewsArticle instance and use that property the same way you would use the CurrentContent property?

    Regards,
    Sasa

  • Matt Taylor 873 posts 2086 karma points
    May 29, 2013 @ 15:00
    Matt Taylor
    0

    Hi Sasa,

    Yes I've considered RenderTemplate and I'm using it elsewhere but I've decided not to here.

    I've decided to declare a property

    public DocumentTypes.NewsArticle Article { get; set; }

    and set that with

    this.Article = ContentHelper.GetByNodeId<DocumentTypes.NewsArticle>(nodeID);

    Then I can use it in my template like so

    <%= this.Article.BodyText%>

    Regards,

    Matt

  • Sasa Popovic 77 posts 367 karma points
    May 29, 2013 @ 15:08
    Sasa Popovic
    0

    Hi Matt,

    Yes, that's exactly what I meant.

    I would just suggest you mark the property as "protected" instead of "public".

    Regards,
    Sasa

  • Matt Taylor 873 posts 2086 karma points
    May 29, 2013 @ 15:12
    Matt Taylor
    0

    Oh yes, thanks.

Please Sign in or register to post replies

Write your reply to:

Draft