How can I use DNNSharp MyTokens in 2SXC Razor templates? - dotnetnuke

I have a content type and C# Razor template for a simple page hero built using 2SXC. I also have a DNNSharp MyTokens with a simple token that looks like this: [DBQ:EligibleForExam]
Using the regular DNN HTML module, I can put my token in the source and it renders the value of the token.
I want to display the value of this DNNSharp MyToken inside of the C# Razor template but it doesn't show the value. Furthermore, I want to perform an if else statement on this value.
Here's what I want to do:
#if [DBQ:EligibleForExam] = 1 {
<p>You are eligible for the exam</p>
}
How can I use DNNSharp MyTokens in 2SXC?

In this case you can choose between going all the way 2sxc or all the way DNNSharp :
- scenario 2sxc: translate the DNNSharp token to 2SXC. I don't know what's behind that code but I guess it is some kind of SQL select and/or filters. In 2SXC you can create content types with SQL as a source. In the query designer, you can filter these results.
- scenario DDNSharp: in MyTokens you create a razorscript or HTML and make a token out of that. I don't think you hit any barriers soon following this path.

The core problem is that tokens are not well architected in DNN, there is no officialy "global" token system which knows about the DNN Sharp tokens.
I believe it should be easy to do though: I'm pretty sure there will be some documentation on DNN Sharp how to use their tokens in any c# or MVC page. Probably just 2-3 lines of code. So best check their docs.

2SXC does not render DNNSharp tokens like html module or EasyDNNSolutions do.
It would be an awesome thing as MyTokens and 2SXC are both very powerfull.
But maybe we can fix your problem within 2SXC itself or within DNN Sharp/HTML
What are you trying to accomplish? You can share the case / code here. Or if you feel this is beyond the Q&A setup that Stackoverflow is, you can send me an email.
Cheers
Tycho

Related

2sxc 13 - Get username and other DNN tokens in formulas/calculations

Is there a way to get the current username in a formula (the v1(data, context) new stuff)? And other DNN tokens as we would on a view.
Current date is easier, since it dependends only on c#, but I can't any documentations for username.
If you are working with Razor templates, yiu can call and and all DNN methods. Also, while editing a template, the dark left column of the edit screen gives you access to all sorts of snippets that you can use by clicking on them.
This feature is still experimental and doesn't do much outside of its context in the browser. We've done a few tests and could not reach outside the Angular app's scope (which makes sense). I do believe there are plans wire up things like that. Daniel will probably chime in.
In the mean time, there is no reason you can't write your own API to get the answers you need from the backend. The formulas aren't limited in any way, so there is no reason not to do it like this (assuming writing your own C# 2sxc WebApi code is something you are familiar with):
async function api()
{
let tmp = await sxc.webApi.fetchJson('/api/2sxc/app/myapp/api/score/progress');
console.log(JSON.stringify(tmp));
}
Just fyi: 2sxc 13.10.02 will have a context.sxc which is great for calling APIs, as well as a context.user.id which will give you some user info. Using this you should be able to get this to work.

Wagtail Form static fields & superuser-only page

I did not found any answer to this. So is there a way in Wagtail to have an AbstractEmailForm without AbstractFormField (for example, can I hard code them into AbstractEmailForm? I know that AbstractEmailField has some variables that Django requires). I just need to have a contact form only with email field, I dont need to set fields dynamically.
And the second question: How do I set permission for that form page so that only superuser can edit the form page?(And the translated version too? There are a lot of answers to this, but I don't actually understand how to do it with AbstractEmailForm).
Thanks a lot!
If you're hard-coding your form fields, then the Wagtail forms module doesn't really give you anything that you don't already get from Django's forms framework, and so you're better off using Django forms directly. The serve method on a Wagtail page is equivalent to a Django view function, so any form-processing logic that would normally go into a view function can be placed in serve.
There's an example of this here (but written for Wagtail 1.x, so imports will need adjusting): https://github.com/gasman/wagtail-form-example/commits/master

2sxc - Getting URL path from DNN link parameter / Tab ID

I am working on integrating a 2sxc content WebAPI feed into a ReactJS application.
I have managed to get a JSON feed of data into the application, and am in the process of mapping out the data.
I'm wondering what the best practice would be to "resolve" a URL which is coming through as a DNN Page/ Tab ID.
Below I will showcase the various points this is referenced...
First the Setup of the entity / data types...
Then this is an example entry with the data filled out... The page link / URL is set up to point to another internal page on the DNN website:
Finally you can see this data item come through as a JSON feed via the 2sxc API:
What is the best way to convert this piece of data into a URL which can be used in a SPA type application?
There isn't any "server-side" code going on, just reading a JSON feed on the client side...
My initial idea would be to parse this piece of data in JS, to extract the number then use something like this:
http://www.dotnetnuke.com/tabid/85/default.aspx
http://www.dotnetnuke.com/default.aspx?tabid=85
I was hoping someone with more experience would be able to suggest a better / cleaner approach.
Thanks in advance
If you were server-side in Razor you'd be doing something like this:
#using DotNetNuke.Common
View List
XXXX = Dnn.Tab.TabID or define a string with the tab id you want
I seem to have a vague memory that I saw somewhere that Daniel (2sxc) has a way to use Globals.NavigateUrl() or similar on the client side, but I have no idea where or if I did see that.
The Default.aspx?tabid=xx format will certainly work, as it's the oldest DNN convention and is still used in fallbacks. The urls aren't nice, but it's ok.
The reason you're seeing this is because the query doesn't perform the automatic lookup with the AsDynamic(...) does for you. There is an endpoint to look them up, but they are not official, so they could change and therefor I don't want to suggest that you use them.
So if you really want a nicer url, you should either see if DNN has a REST API for this, or you could create a small own 2sxc-api endpoint (in the api folder) just to look that up, then using the NavigateURL. Would be cool if you shared your work.

Loading Facelets templates from database

In my application (CMS for internal purposes) I'm facing the problem how to serve pages stored in the database with dynamic URL (e.g. http://example.com/page3) using the JSF. Generally, let's say I want to grab the page content from the database, put it inside jsf file and serve it as /page3. Is there any way how to obtain the request URL from JSF, search the database for the article (instead of searching *xhtml in the WAR), build dynamically the JSF XHML file and return it to JSF as InputStream for example? I've found this answed by Thomas Maerz, but it failed with
Unable to create a new instance of 'com.test.CustomResourceResolver': java.lang.InstantiationException: com.test.CustomResourceResolver
on my glassfish v4 (Mojarra 2.2), and I also found that ResourceResolver is deprecated in JSF2.2.
I've googled a lot, but this seems to be not very common/documented part of JSF.
Thank you for any help.
I did not understand fully the problem, but for url change you can use prettyfaces, for dynamic forms you can use primefaces ext and I am not suggest keep form in the database, if I know your target I can suggest more useful answer.

ASP.NET 3.5 webforms URL Routing question

I'm attempting to configure URL routing in my ASP.NET 3.5 WebForms app. Setting up routes has always been confusing to me, so I was hoping I could get some direction.
My requirement is fairly simple. I'm setting up different "brands" of my application, and I'd like the brand to be specified in the URL. For example, http://www.mysite.com/brand1/Default.aspx would bring up one brand (code behind would look up brand1 in the db and load specific text, images, themes, etc) and http://www.mysite.com/brand2/Default.aspx would bring up another brand, etc.
I'm fairly flexible with how the URLs are displayed, with the exception of keeping the http://www.mysite.com/brand1 prefix. That cannot be changed.
Thanks for any help!
I do this by using http://www.UrlRewriter.net, as explained here by Scott Gu:
http://weblogs.asp.net/scottgu/archive/2007/02/26/tip-trick-url-rewriting-with-asp-net.aspx
The trick is to use URL rewriting rules (Regular Expressions) in your web.conifg to get a request for /brand1/default.aspx to actually execute /Processor/Default.aspx?brand=brand1, for example.
NB: The Form.browser trick worked a treat for me when doing postbacks.
Another possible answer from me...
If you're using IIS 7 there is a handy built in module for URL Rewiring, all controlled through a GUI if that's your preference:
http://learn.iis.net/page.aspx/460/using-the-url-rewrite-module/

Resources