Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 730359
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T06:54:10+00:00 2026-05-14T06:54:10+00:00

I am using string template to render some content, but the content may be

  • 0

I am using string template to render some content, but the content may be variable so not sure how to pass it in (using .net / c#)

Basic idea is I have a List> which need to end up as parameters, e.g.

List<KeyValuePair<string, object>> ret = new List<KeyValuePair<string, object>>();
ret.Add(new KeyValuePair<string, object>("elem1", true));
ret.Add(new KeyValuePair(string, object>("elem2", false));

Now I want these to show up in string template as:

$item.elem1$
$item.elem2$

I can get them to be $elem1$ or $elem2$ but i need them inside of a structure. So I in effect need to convince the string template setAttribute that I’m passing in an object with properties elem1 and elem2 when in fact I have a List of KeyValuePairs.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T06:54:10+00:00Added an answer on May 14, 2026 at 6:54 am

    Actually a very small re-write of that should work. You need to use a dictionary, and you can even nest them (using ST 3.2):

    [Test]
    public void When_Building_Text_With_A_Dictionary_As_The_Attributes_It_Should_Map_Members_To_Keys()
    {
        IDictionary<string, object> ret = new Dictionary<string, object>();
        ret["elem1"] = true;
        ret["elem2"] = false;
    
        var nestedObj = new Dictionary<string, object>();
        nestedObj["nestedProp"] = 100;
        ret["elem3"] = nestedObj;
    
        var template = new StringTemplate("$elem1$ or $elem2$ and value: $elem3.nestedProp$");
        template.Attributes = ret;
    
        StringBuilder sb = new StringBuilder();
        StringWriter writer = new StringWriter(sb);
        template.Write(new NoIndentWriter(writer));
        writer.Flush();
    
        var renderedText = sb.ToString();
    
        Assert.That(renderedText, Is.EqualTo("True or False and value: 100"));
    }
    

    Myself and a colleague were looking to replicate the functionality of STST (ST Standalone Tool), which uses json as the properties, and we built a simple JObject to dictionary converter, I can post that code and an example if it’s of any use to you, it’s only ~20 lines.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is their a solution to generate an email template using an ASP.NET MVC View
I'm trying to wrap content with some static HTML in MVC and I'm not
I'm using Tornado and I want to load some static files in the template.
I can make the same in Django using render_to(...) but ASP.NET. I need to
I have some problem with writing a Method in the template pattern style. But
I am not actually using the Razor from ASP.NET MVC, I am using the
I've got a CMS that takes some dynamic content and renders it using a
I'm using mustache to render stuff on the server, but also on the client.
For some years that I've been using my own PHP template engine, which is
I'm using StringTemplate V4 to generate some HTML code in my project. I need

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.