Copied to clipboard

Flag this post as spam?

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


  • Oluwole Kolawole 32 posts 53 karma points
    Feb 26, 2011 @ 06:18
    Oluwole Kolawole
    0

    User Control Parameters on a content page

    Hi everyone,

    This is a newbie question so please bear with me.

    I created a user control using Visual Studio and was able to include it successfully as a macro in Umbraco. I can then reference that macro in a template and specify values for its public properties.

    My problem is this. The users that will eventually update content should not be changing parameter values in templates. So is there any way to specify this macro (or just its parameters) as a property on a document type so that a user can enter values for those parameters?

    What I'm really trying to do is place my user control at several different places on the template and for each instance allow the user to enter different values for the controls' parameters (three parameters per instance).

    I fully accept that I'm probably not going about this the right way :-).

    Thanks.

    Wole.

    PS: I'm using Umbraco 4.6.1 and VS2008.

  • nelsenlim 70 posts 71 karma points
    Feb 26, 2011 @ 07:49
    nelsenlim
    1

    Use

    Node.GetCurrent().GetProperty("propertyName").Value

    in your ascx.cs to get the value of the property for the currently browsed node

  • Oluwole Kolawole 32 posts 53 karma points
    Feb 26, 2011 @ 16:31
    Oluwole Kolawole
    0

    Hi b_t3t, thanks for your reply. Unfortunately it appears you have mis-understood my question. My c# usercontrol has public properties which I can easily provide values for when the control is added as a macro in a template...no problems there.

    The problem is, the user that will be modifying the content will not have access to change templates and therefore the values passed to the usercontrol should not be hard-coded into the template.

    Perhaps I should be looking at a custom datatype instead! Thoughts anyone?

    Wole.

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Feb 26, 2011 @ 17:49
    Jan Skovgaard
    0

    Hi Oluwole

    If I understand you correctly then it's possible to feed the macro with content from the content section using this syntax on the macro...

    soemparameter="[#bodyText]" - This fetches the content from the a rich text editor for instance, which is stored on the template that the current visited page is using.

    Does this make sense to you?

    /Jan

  • Chris 69 posts 75 karma points
    Feb 26, 2011 @ 17:52
    Chris
    1

    You could create a property for each of your params in your document type and pass the values of them by using this syntax:

    <umbraco:Macro param1="[#property1]" param2="[#property2]" param3="[#property3]" Alias="YourMacro" runat="server"></umbraco:Macro>

     

     

    In this case, the user can update the values from the content section

     

  • Oluwole Kolawole 32 posts 53 karma points
    Feb 26, 2011 @ 18:04
    Oluwole Kolawole
    0

    Thanks Jan and Chris,

    This makes sense...I would have preferred to be able to put the usercontrol on the template then have Umbraco 'automagically' present input boxes to the user when they edit the page, but I guess that will be asking for a complete re-design of the way Umbraco works :-).

    Your suggestions are the next best thing. Thanks.

    Pity I can't mark both of your answers as the solution...so Jan, you get the tick.

    Wole.

  • Oluwole Kolawole 32 posts 53 karma points
    Feb 28, 2011 @ 00:31
    Oluwole Kolawole
    0

    Hi guys,

    It turns out that I was too hasty in dismissing b_t3t's answer to my question; my sincere apologies. It happens that that suggestion was exactly what I really needed, I just didn't know it at the time being so new to Umbraco.

    Using Node.GetCurrent().GetProperty("propertyName").Value allows me to read the value of any property entered by the user on the current content node (page). Doing it this way means that I don't even need public properties in my usercontrol, I just read whatever property I need from the current node. Works a treat :-).

    @b_t3t: You were spot on mate, cheers.

Please Sign in or register to post replies

Write your reply to:

Draft