Portal Engine Questions on portal engine and web parts.
Version 4.x > Portal Engine > Adding custom id for news View modes: 
User avatar
Member
Member
oli.acev-yahoo - 5/19/2010 3:40:05 AM
   
Adding custom id for news
I want to use custom news like NewsDetails.aspx?ID=5 instead title my-first-page.aspx

Please help

User avatar
Kentico Support
Kentico Support
kentico_zdenekc - 5/25/2010 10:18:39 AM
   
RE:Adding custom id for news
Hi,

Yes, that's possible. You can setup a page, named let's say "NewsDetails", and place here a repeater with transformation set to News detail transformation. Then you would use query string macro expression (denoted with questionmarks) for the "Where condition" property, in order to be like

NewsID = {%ID%}


(supposing you're using default News document with NewsID field)

In the news listing, you will also need to render the links not with the document name, but with the NewsDetails page path and querystring parameter with value based on the NewsID.

Regards,
Zdenek C.

User avatar
Member
Member
oliveracev-yahoo - 5/25/2010 4:04:35 PM
   
RE:Adding custom id for news
Because I'm the medium expert in Kentico please can you describe me precisely where, what and which code I need to put and how

Thank you in advice

User avatar
Kentico Support
Kentico Support
kentico_zdenekc - 5/31/2010 10:56:52 AM
   
RE:Adding custom id for news
Well, it's really not so difficult.

You can create a transformation for your News document, let's say with name "NewsLinks".
In that transformation, which would be used in the Repeater for news list, you can build links like:
<a href="~/NewsDetail.aspx?ID=<%# Eval("NewsID") %>"><%# Eval("NewsTitle") %></a>
// you may need to use absolute path instead of "~" symbol.

Then, you would create a page with alias path .../NewsDetail (i.e. live url ".../NewsDetail.aspx").
In this page (template), you would use Repeater with transformation set to the "NewsDetail" transformation and in the Where condition property of the repeater, use simply a macro expression:
NewsID = {%ToInt(ID, "0")%}

Hope this will work for you...

Regards,
Zdenek

User avatar
Member
Member
oliveracev-yahoo - 6/4/2010 4:44:39 AM
   
RE:Adding custom id for news
Thank you for your reply, but I have some problems. I will describe here what I have been maked.

First I was maked page "newsdetail then in the development > document types i was created transformation in CMS.News document like this:
<div class="item">
<div class="article">
<div class="newslistMonth">
<%# GetDateTime("NewsReleaseDate", "dd MMM, yyyy") %></div>
<H3> <a href="/mnr/NewsDetail.aspx?ID=<%# Eval("NewsID") %>"><%# Eval("NewsTitle") %></a> </h3>
<div class="intro">
<div class="author"><%# Eval("NewsAutor") %></div>
<%# Eval("NewsSummary") %>
</div>
</div>
<div class="clear"></div>
</div>
<div class="hr"><hr></div>

Then in the page named newsdetail i was added repeater with path to this page, document types to CMS.News and transformation to path where is this code up and in where condition: iwas added that code NewsID = {%ToInt(ID, "0")%}

Problem is thah I have blank page on this module
Where is my mistake???

User avatar
Kentico Support
Kentico Support
kentico_zdenekc - 6/7/2010 3:15:00 PM
   
RE:Adding custom id for news
Hi,

I'm not fully sure which path has been set for the news listing repeater and which for the detail page repeater, they should be the same...
The path in both repeaters should point to the node, whose child nodes are the news documents, e.g. something like "/News/%"
The where condition in the detail repeater then just limits the result to 1 news document only.
If you have the path set to the .../NewsDetail/ node, it's not correct, unless there are all the news documents underneath it.

The content structure may look like:
...
News (repeater with transformation for links, path set to "/News/%")
L...news 1
L...news 2
|...
...
NewsDetail (repeater with detail transformation, path set to "/News/%" and wherecondition with that newsID macro)
...

Hope this helps.

Regards,
Zdenek

User avatar
Member
Member
oli70it - 3/25/2011 5:07:27 AM
   
RE:Adding custom id for news
I can't to fix this, let's start again

First of all I was created two transformation in news documents where
Document alias source field is set to NewsID

1. NewsListing
2. NewsDetail

In NewsListing transformation I was added this code
<a href="/KenticoCMS/News.aspx?ID=<%# Eval("NewsID") %>"><%# Eval("NewsTitle") %></a>

In NewsDetail transformation I was added this code
<h1><%# Eval("NewsTitle") %></h1>
<%# GetDateTime("NewsReleaseDate", "d") %><br/>
<%# IfEmpty(Eval("NewsTeaser"), "", GetImage("NewsTeaser")) %>
<%# IfEmpty(Eval("NewsSummary"), "", Eval("NewsSummary") + "<br />") %>
<%# Eval("NewsText") %>

Thats for this

Next in CMSDesk
I was created page name News.aspx with template name News
Under News .aspx I created my news1, news2, news3 documents with template NewsDetail

On the Page.aspx I was added Repeater with this settings
- Path: /News/%
- Document types: CMS.News
- ORDER BY expression: NewsReleaseDate DESC
- WHERE condition: NewsID = {%ToInt(ID, "0")%}
- Transformation: CMS.News.NewsListing
- Selected item transformation: CMS.News.NewsDetail

On the NewsDetail template I was added another Repeater for with this settings
- Path: /News/%
- Document types: CMS.News
- Selected item transformation: CMS.News.NewsDetail
- Select top N documents : 1

Is this OK configurations???

Thanks in advance

User avatar
Kentico Support
Kentico Support
kentico_zdenekc - 4/5/2011 1:14:49 PM
   
RE:Adding custom id for news
Hello,

Well, this setup is a little bit confusing for me...

First of all I don't know why you're setting Document alias source field to NewsID.
You don't use this anywhere then...

I think that the NewsDetail template should match the setup of the Page.aspx, because it selects only the specific News document using ID in querystring.

Also, when you're using two repeaters in separate pages, one for listing and one for details, usage of SelectedItemTransformation doesn't make sense. Please use only standard Transformation.

Also it's almost useless to define any template for particular News documents, when you won't be accessing them directly...
In the listing transformation, you're pointing to the News.aspx page with the ID parameter, so there should be the repeater displaying news details as well. It's pointing to the same location where the listing repeater is placed...
Therefore you have to arrange two repeaters in the same template for News.aspx page, and hide the listing repeater when there's any valid ID querystring parameter.

You can do this by macro in "Visible" property: {%ToInt(ID, "0") == "0"%}
This will hide the listing repeater when there's a valid ID.

Oppositely, you want to hide the detail repeater when the ID is not present... the Visible property could be then {%ToInt(ID, "0") != "0"%}

Please also use the WHERE condition from the Page.aspx definition in your detail page repeater and set the CMS.News.NewsDetail transformation as standard Transformation in this repeater. Top N doesn't have to be used, since where condition picks up only one document anyway.

Hope it makes sense.

Regards,
Zdenek

User avatar
Member
Member
adilmahmood8800-yahoo - 5/6/2013 2:56:05 AM
   
RE:Adding custom id for news
hi sir ,

sir i want to display a specific news against read more link ........
<a href="News.aspx">read more</a>

i am using this .....bt my poblem not resolve..................
<a href="~/NewsDetail.aspx?ID=<%# Eval("NewsID") %>"><%# Eval("NewsTitle") %></a>
NewsID = {%ToInt(ID, "0")%}

how we con use this in wher clause and fill the span how we can............................for example
 DataSet ds = new DataSet();
SqlConnection con = Connection.GetConnection();
con.Open();
SqlDataAdapter da = new SqlDataAdapter("select * from News_tb where NewsID = {%ToInt(ID, "0")%} l", con);
da.Fill(ds);
// Image2.ImageUrl = ds.Tables[0].Rows[0][5].ToString();
Span1.InnerText = ds.Tables[0].Rows[0][1].ToString();
Span2.InnerText = ds.Tables[0].Rows[0][2].ToString();
Span3.InnerText = ds.Tables[0].Rows[0][4].ToString();

and rows[0] how we can eplace accoding to NewsId....

User avatar
Kentico Consulting
Kentico Consulting
Kentico_RichardS - 5/7/2013 1:42:07 AM
   
RE:Adding custom id for news
Hi,

I dont fully understand your question. Could you please describe further what exactly are you seeking? What do you want to do with the "read more" link and how should it behave?

Thank you for more information.

Kind regards,
Richard Sustek

User avatar
Member
Member
adilmahmood8800-yahoo - 5/7/2013 4:15:47 AM
   
RE:Adding custom id for news
hi ,
sir my latest news headline display on my my index page.and a link "read more" attach
for further description....in index page 3 top news are displayed...and 3 "read more" link for each news how we can identify the what read more link is click and which news description is displayed......

i am using this code but they can not properly work............
<a href="~/NewsDetail.aspx?ID=<%# Eval("NewsId") %>"><%# Eval("NewsTitle") %></a>

and NewsDetail.aspx page use this code.......
SqlDataAdapter da = new SqlDataAdapter("select * from News_tb  where NewsID = {%ToInt(ID, "0")%}  l", con);
da.Fill(ds);
// Image2.ImageUrl = ds.Tables[0].Rows[0][5].ToString();
Span1.InnerText = ds.Tables[0].Rows[0][1].ToString();
Span2.InnerText = ds.Tables[0].Rows[0][2].ToString();
Span3.InnerText = ds.Tables[0].Rows[0][4].ToString();

Thank you
Adil Mahmood

User avatar
Kentico Support
Kentico Support
kentico_zdenekc - 5/17/2013 11:03:07 AM
   
RE:Adding custom id for news
Hi,

I'm afraid the querystring macro expression cannot be used in the code directly. It has to be resolved manually using appropriate API. If you want to get values out of the querystring, you can use QueryHelper.GetString or .GetInteger methods.

Anyway, I believe there is far easier way. You could just use the Where condition in the repeater or whatever listing web part (or control) in the NewsDetail.aspx page. There it should be possible to simply use the where condition with macro like you're trying in the code:
NewsID = {%ToInt(ID, "0")%}

Hope this will help.

Regards,
Zdenek