Re: [Cppcms-users] Template rendering. Access the actual class, rather then members?
Brought to you by:
artyom-beilis
|
From: Artyom B. <art...@ya...> - 2014-07-16 07:33:47
|
I'm not 100% sure I understood your question. If you need to pass a complex structures you can part them as a member of "content::message" if you want to access the object itself. What do you expect to do with it? If you access an object you access its members. Now technically <% = text %> is converted to C++ code like: out() << content.text; (not exactly as there are filtering and some more stuff) so if you embed C++ to the code you can actually access c as "content" variable. Now one important restriction is that "c" is actually derived from cppcms::base_content http://cppcms.com/cppcms_ref/latest/classcppcms_1_1base__content.html Which is polymorphic class and safe dynamic casting can be done to ensure you actually use right object withing the template. Note templates may be loaded dynamically and compiled independently. Artyom Beilis -------------- CppCMS - C++ Web Framework: http://cppcms.com/ CppDB - C++ SQL Connectivity: http://cppcms.com/sql/cppdb/ >________________________________ > From: Abhishek Kaushik <abh...@gm...> >To: cpp...@li... >Sent: Monday, July 14, 2014 7:16 PM >Subject: [Cppcms-users] Template rendering. Access the actual class, rather then members? > > >Greetings, > >I have been following the CPPCMS tutorials regarding view rendering. > >What I see mostly is that when you render your data (let's use the example >of content::message) > >so we have: > > content::message c; > c.text=">>>Hello<<<"; > render("message",c); > >and then in the templates, we use this data as: > ><% view message uses content::message %> ><% template render() %> ><html> > <body> > <h1><%= text %> World!</h1> <-- this is a part of message. > </body> ></html> ><% end template %> ><% end view %> > >========================== > >What I wanted to know, is there a way to access "message" object in the >template, directly? Like instead of doing: > ><%= text %>, is there any way where I can refer the actual parent object: >like <%= message.text %> ? > >The advantage I will have is, that while calling the render method (as in >render("message",c);), I would be able to pass my data directly. > >Let's say in the Message Board's Example. If you see the passing of >data::forum to templates, you were required to construct a parent kind of >object, which would contained vectors to topics, etc. But if you see from >the usage or design point of view, it would be great if I were able to pass >the topics directly, without making it require a parent kind of wrapper. > >Let me know, if there exists any way to achieve it. > >Regards, >Abhishek > > >------------------------------------------------------------------------------ >Want fast and easy access to all the code in your enterprise? Index and >search up to 200,000 lines of code with a free copy of Black Duck® >Code Sight™ - the same software that powers the world's largest code >search on Ohloh, the Black Duck Open Hub! Try it now. >http://p.sf.net/sfu/bds >_______________________________________________ >Cppcms-users mailing list >Cpp...@li... >https://lists.sourceforge.net/lists/listinfo/cppcms-users > > > |