Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeDNN Open Source...DNN Open Source...Module ForumsModule ForumsRepositoryRepositoryCustom Tags/TokensCustom Tags/Tokens
Previous
 
Next
New Post
6/30/2008 7:24 PM
 

Hello,

I am trying to use the repository module to host some files and associate some metadata to it in the form of tags pertaining to properties of the file. I intend for these tags to be inputted by the end-user. I am aware that I will have to add these tokens myself in the source code and recompile it. However, I am not sure where to start with this. Is there a single file where I need to make the changes or do I have to rewrite code in a lot of places?

Thanks.

 
New Post
7/1/2008 8:59 AM
 

nope, just one spot.

Before you begin though, please read the pinned post in this forum "HOW TO: Making code changes and recompilling the Repository module 3.x", it is really important to understand the process of changing the module, as it's a .net 1.1 assembly.

So, if you're ready to go, here's how to add a new token to the 3.x version of the Repository module...

All changes will be in the Repository.ascx.vb file.

There are 5 functions that parse/process templates, 1 for each section of a template

ParseHeaderTemplate() - parses/process tokens for the header section defined in header.html/header.xml

ParseFooterTemplate() - parses/process tokens for the footer section defined in footer.html/footer.xml

ParseRatingTemplate() -  parses/process tokens for the rating form section defined in ratings.html/ratings.xml

ParseCommentTemplate() -  parses/process tokens for the comment section defined in comments.html/comments.xml AND viewcomments.html/viewcomments.xml

lstObjects_ItemDataBound() - parses/process tokens for each individual data item being displayed as defined in template.html/template.xml

Decide which section of the overal template you want your new token to be available in, or if you want to make it available in multiple sections, for example, most tokens in the header section are also available in the footer section

The process is exactly the same for each section, so I will show you how to add a new token to the individual data item section, template.html/template.xml by editing the lstObjects_ItemDataBound() function.

In the function, you'll see a large "Select" statement based on the sTag variable. That is the main token processing code. There is a "Case" statement for each token, so to add support for a new token, just add a new 'Case" statement.

The basic logic within each case statement is to dynamically create the control you want to replace the token with at runtime, and add it to the controls collection of a place holder control named 'objPlaceHolder'. In the following example, I will replace the token named 'MyToken' with some static text.

' add new token named, MyToken
Case "MyToken"
  Dim objLabel as New Label
  objLabel.Text = "This is my new Token"
  objPlaceHolder.Controls.Add(objLabel)

Attributes:
You can allow a user to apply 'attributes' to your tokens by adding settings to the corresponding xml file. For example, if we want to be able to apply a stylesheet class to our token, we need to add some code to look at the xml file and see if there's a setting for the attribute and if so use it, or if not, use some default value. The function to do this is oRepositoryBusinessController.GetSkinAttribute(xmlFile, tokenName, settingName, defaultValue).

So, calling...

oRepositoryBusinessController.GetSkinAttribute(xmlDoc, "MyToken", "CssClass", "Normal")

 will open the template.xml file, look for the [MyToken] token node, see if there's a "CssClass" setting node, and if so, will return the value. If there is no token, or no setting, then the function will return the defaultValue, "Normal".

To use this function to set the CssClass attribute on our example label control, the code would look like this...

' add new token named, MyToken
Case "MyToken"
  Dim objLabel as New Label
  objLabel.Text = "This is my new Token"
  ' apply CssClass attribute
  objLabel.CssClass = oRepositoryBusinessController.GetSkinAttribute(xmlDoc, "MyToken", "CssClass", "Normal")
  objPlaceHolder.Controls.Add(objLabel)
 

To override the default value of "Normal", add a token node to the template.xml file like this... in this example, the label that will replace your MyToken token will be rendered using the SubHead class.

 <Object>
  <Token>[MyToken]</Token>
  <Settings>
   <Setting>
    <Name>CssClass</Name>
    <Value>SubHead</Value>
   </Setting>
  </Settings>
 </Object>

You can add any control type to the place holder control collections, so tokens can range from simple data replacement to advanced complex controls ( like the rating input form control ).

Good luck, if you have any questions or problems, just ask.

 

 
Previous
 
Next
HomeHomeDNN Open Source...DNN Open Source...Module ForumsModule ForumsRepositoryRepositoryCustom Tags/TokensCustom Tags/Tokens


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out