Pulling content from DB

Sep 19, 2014 at 10: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 :)
Coordinator
Sep 19, 2014 at 10: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!
Daniel
Sep 19, 2014 at 10:16 AM
manight

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
Coordinator
Sep 19, 2014 at 10:17 AM
@nokiko

This has a few ties together with some other features we're looking into in 6.4. My guess in 2-4 weeks.
Coordinator
Sep 19, 2014 at 10:18 AM
...documented in this issue
Sep 19, 2014 at 11:06 AM
Edited Sep 19, 2014 at 12:09 PM
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
Coordinator
Sep 19, 2014 at 12:28 PM
We recommend either getting this from the web.config...
...or if you need a custom connection, use App settings.
Sep 19, 2014 at 4: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)
        con.Open();
        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
Coordinator
Sep 22, 2014 at 7:26 AM
The [Content:Top5] would be Tokenns syntax.

In Razor, you would write
if(Contet.Top5) 
{
   ...
}
And when using inline for output the "shorthand" for Response.Write is @Content.Top5
Sep 22, 2014 at 12:22 PM
it works beautifully... thanks for your great piece of software!
Coordinator
Sep 22, 2014 at 12:32 PM
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 12:52 PM
I would buy even if it was not free. Going to do it right now. Thanks for your great support also.
Coordinator
Sep 22, 2014 at 2:18 PM
awesome, thanks!
Sep 22, 2014 at 2:27 PM
@manight

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 5: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!
Thanks