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

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.

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.

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

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

What is the best way to implement dual (server side) rendering with MarionetteJs?

I can I implement following workflow with MarionetteJs:
User opens site by URL
Server generates HTML + JSON data
MarionetteJs reads JSON data and "attaches" to generated HTML. So it doesn't rerender templates.
User do something -> MarionetteJs updates DOM, sends server requests, etc
So the main problem for me is 3 - attach point. What is the best way to implement dual rendering with MarionetteJs?
This is something that hasn't been baked in to Marionette, yet. I've seen a number of other people solve this for Backbone in general, and it might be easy enough to take their solutions in to account.
Hopefully someone will have an answer for you, though. I'd love to see an add-on or plugin, or pull request to the project for this.

Dynamic ISAPI ReWrite

I have a few websites that could benefit from some URL rewriting. I understand that a map file is needed, but as the data is dynamic, is there a way to call from an SQL database instead of a static file?
Using ISAPI Rewrite via IIS7
eg
unfriendly - www.domain.com/products.asp?prodID=1
Friendly - www.domain.com/products/Apples
Any examples or pointers would be apprecaited.
thanks in advance.
C :-)
one possible solution is to do this with a custom 404 handler... when the user hits /products/apples the 404 handler picks it up, does a database lookup and matches that back to prodID=1 and displays the right content.
it's not particularly elegant but it works (I've used it in the past and as long as you remember things like returning the right HTTP response headers for content vs a genuine 404 you should be okay)
Most folks end up using something like ISAPI_Rewrite
Create a new .asp page that retrieves the product using the url name of the product. The new page should be similar to your existing products.asp page but instead of getting the product using the id, you are getting the product using the unique url name.
RewriteRule ^products/(.*)$ /productfromurlname.asp?urlname=$1 [NC,L]
This way:
/products/apples --> /productfromurlname.asp?urlname=apples
/products/oranges --> /productfromurlname.asp?urlname=oranges

DotNetNuke -- Inserting URL parameters in forms

We are migrating our website to DotNetNuke and are looking to replicate the functionality of our survey page. Currently, on the bottom of every e-mail we send through our CRM system, there is a link to a satisfaction survey along with some parameters to pre-populate some of the fields. So the URL looks something like like:
/survey.aspx?ticketID=1234&userName=John+Doe
I found the custom module "helferlein_Form" which seems okay for actually creating the form that the user fills in, but I don't see a way to pre-populate the fields. DotNetNuke does let you insert tokens(ex: [Date:now], [User:username]), but I don't see a way to grab individual parameters from the URL. Is there something I'm missing that will let me do that?
I'm not familiar with that module either, but I would strongly recommend using Xmod for customized forms that allow you to easily grab url parameters.
I'm not sure about the module you reference.
However, in my experience Dynamic Forms from Data Springs would fit the bill perfect. It has the ability to pre-fill and even run custom SQL queries to get data.
You should definitely try our My Tokens module.
It allows you to access the URL parameters using [Get:ticketID] or [QueryString:tickedID]. You can also build SQL tokens that use these parameters to return a list of items for example to populate a dropdown.
Also try our Action Form module which integrates very nice with My Tokens.
If you have a module you like and want to use you can always write a little javascript to grab the variables out of the URL and pre-populate your form fields using javascript.

Resources