Pulling content from DB

Sep 19, 2014 at 9:07 AM
First of all thanks for your great job! I watched your SQL tutorials with Razor and datareader, petapoco and so on… the only thing I didn’t understand is… when I create a template I’m asked to bind it to a content, but which content should I choose for that purprose?
When I create “content types” thery are just strings or such there is no such thing like a “db pulled” content to associate the template with :)
Sep 19, 2014 at 9:12 AM
Hi manight

The Content concept is this: usually every module has some kind of content. Often it's a title/text/picture or a customer-name/quote/address/telephone/screenshot or something. This is content that is fully managed by 2sxc.

When you create a template that is more data oriented, then content is usually some kind of configuration - like parameters in the SQL query. A typical example would be
  1. Title
  2. SortOrder
  3. CategoryFilter
...something like that. These are quickly created in your content-types, and then assigened. Please also look into the demo-content-item concept, this helps new users add the view and immediately have some pre-defined parameters so the query can already run without him specifying anything.

Have Fun!
Sep 19, 2014 at 9:16 AM

This is one shortcoming that still needs to be addressed :) templates not assigned to a content type because it uses other data

what I do i just create a content type called dummy give that the a title and add one dummy item and use that as the content and initial content for the template

this way your script will run

@Daniel when can we expect a settng that we can disable the needed content type for a tempalte
Sep 19, 2014 at 9:17 AM

This has a few ties together with some other features we're looking into in 6.4. My guess in 2-4 weeks.
Sep 19, 2014 at 9:18 AM
...documented in this issue
Sep 19, 2014 at 10:06 AM
Edited Sep 19, 2014 at 11:09 AM
Ok now it's clear... thanks both. I tried with a dummy content but the content was shown instead of my template for sure I did some mistake... I will try again.
Nonetheless the ability to use content like "variables/parameters" to customize the razor template on the fly is wonderful!
You did really a great piece of stuff here.

One thing I still miss is the Connection String.... Is this some default thing pulled from DNN main connection string or do I have to specify it somewhere? EDIT: Sorry stupid question... is in the SQL Templates sorry
Sep 19, 2014 at 11:28 AM
We recommend either getting this from the web.config...
...or if you need a custom connection, use App settings.
Sep 19, 2014 at 3:57 PM
To see i I got all this right I was trying to get some parameters from a string content. I defined an item "Top5" as a string and 3 records "comments", "rated", "views"

Then in the template I have (taken from datareader example)
        var command = "";       
        if ([Content.Top5] == "views") { command = new SqlCommand("Select Top 5 [Title], [ArticleImage], [DetailTarget], [NumberOfViews], [NumberOfComments], [RatingValue], [RatingCount], [PublishDate] from....", con) }
        if ([Content.Top5] == "comments") { command = new SqlCommand("Select Top 5 [Title], [ArticleImage], [DetailTarget], [NumberOfViews], [NumberOfComments], [RatingValue], [RatingCount], [PublishDate] from ...", con) }
        if ([Content.Top5] == "rated") { command = new SqlCommand("Select Top 5 [Title], [ArticleImage], [DetailTarget], [NumberOfViews], [NumberOfComments], [RatingValue], [RatingCount], [PublishDate] from...", con) }
command.Parameters.Add("@PortalId", Dnn.Portal.PortalId);
Is this correct and should work with the beahviour I understood? I set views as demo content.
For some reason I get this error and razor doesn't seem to appreciate the tokens "error CS1525: Invalid expression term '[' at ..."

If I remove the if([Content.Top5].....) and just leave the SQL command string everything works perfectly
Sep 22, 2014 at 6:26 AM
The [Content:Top5] would be Tokenns syntax.

In Razor, you would write
And when using inline for output the "shorthand" for Response.Write is @Content.Top5
Sep 22, 2014 at 11:22 AM
it works beautifully... thanks for your great piece of software!
Sep 22, 2014 at 11:32 AM
Your welcome!
and please help us too - "buy" it (for free) in the store and then rate it with 5 stars - so that others will trust the product and try it too :)
Sep 22, 2014 at 11:52 AM
I would buy even if it was not free. Going to do it right now. Thanks for your great support also.
Sep 22, 2014 at 1:18 PM
awesome, thanks!
Sep 22, 2014 at 1:27 PM

If you want to spend money :) I can still use co sponsors for a Razor-API ( custom admin forms, non registred user input ( liek a rating or review system for 2scx items and lots more ) Allow you to do stuff like CreateEntity(entityTypeName, Values[])

possibly interested?
Sep 22, 2014 at 4:27 PM
At the moment I'm totally committed to a single project I have to carry on so I really don't have "energies" to spend around. It was a big effort for me to take a little dive into 2scx and I was lucky enough that I found what I was looking for. I didn't understand very well what are you proposing/talking about but if you'll setup some page please provide links and when this chaos will pass I will take a look for sure!