Trying to get the routeName but it's always empty - html

I tried to get the routeName from the URL because i need to set another class in the Layout of the body if i'm on the /Category page.
#{string classContent = Request.QueryString["routeName"] != "/Category" ? "container" : "";};
<div id="Content" class="body-wrapper #classContent">
My problem is, Request.QueryString["routeName"] is always empty and couldn't find why.
Does someone know why it's always empty or has a better approach for setting a different class if you're on a certain page?

In the end i solved it with that code:
var segments = Request.Url.AbsolutePath.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
string classContent = "container";
if (segments.Count() > 1) { classContent = segments[1] != "category" ? "" : "container";}
Request.Url.AbsolutePath gets the whole URL.
After that i split the whole URL and save it into a list.
Then i test if the list is long enough to be on another site except home.
In the end i look if the second part of the url is /Category and save the Css class appropriate to the output of the url.

Related

Typoscript: render HTML table with database values

Im completely new to typoscript therefore I have quite a hard time with the syntax but I think I am getting there.
My task is to render an HTML table and fill it with values from a database table (doesn't matter which one). In my case I took the tt_content table and tried to fill my HTML table with the "header" field and the "bodytext" field.
So I made a completely empty template and wrote the following code in the "setup" field of the template. I added some headers and texts to the sites I have to test my code but I get a completely empty page not even the "table" HTML tags are there.
After 4 days of research I still don't know what my problem is here so I am quite desperate.
Here is what I have so far:
page = PAGE
page.typeNum = 0
lib.object = COA_INT
lib.object {
10 = TEXT
10.value = <table>
20 = CONTENT
20.wrap = <tr>|</tr>
20 {
table = tt_content
select {
orderBy = sorting
}
renderObj = COA
renderObj {
10 = COA
10 {
10 = TEXT
10 {
field = header
wrap = <td>|</td>
}
20 = TEXT
20 {
field = bodytext
wrap = <td>|</td>
}
}
}
}
20 = TEXT
20.value = </table>
}
If someone could help me out here it would be much appreciated.
Thanks in advance.
Check if you have any 'template parser' running.
go to template -> choose 'Info/modify' and click on 'edit the whole ...'
There choose the includes tab and include css_styled_content' (Yes, there is another way of parsing your content, with fluid_styled_content'. you can choose that instead if you are on TYPO3 7.6.* or higher)
These 'parsers' will give you all the needed typoscript included to parse and render your content. Without these, nothing will be rendered when you want to render content from the backend.
second: your typoscript is wrong
You have made a content array (lib.content is a Content Object Array) and filled it with content. But you overwrite the content with key 20.
change
20 = TEXT
20.value = </table>
to
30 = TEXT
30.value = </table>
third: you have created a Page object but you did not add your COA into that page object.
Try this:
page = PAGE
page.10 < lib.object
What this does is include your lib.content in the Page Object at 'level' 10
you can also do
page.20 = TEXT
page.20.value = hello world
This will be rendered after your lib.content.
As you could notice. It is a bit as writing a big Array (because typoscript is a big Array ;)
Beware that you place your lib.content ABOVE the page object declaration. else it will not be able to include it.
There is also a slack channel for TYPO3 you can join if you have other questions. People over there are more then willing to help you.
https://forger.typo3.org/slack

TYPO3 templates and changes the div id

I have a Template in TYPO3 that i want to use to some pages, in here i have a DIV.
Is it possible depending on the page UID, to changes the DIV ID. its the only div thats changes content/image, and im looking to put this DIV inside my main.html template.
so if
UID = 2 <div id="topbanner_about"></div>
UID = 3 <div id="topbanner_drills"></div>
and so on....
Can i do this, and can i do it in TS (Typo Script) or how can i do this, so i dont need to make 5 templates.
You can do this by inserting a marker in your template. It would look somehow like this:
In the template:
[...]
<div id="topbanner_###ID_SUFFIX###"></div>
[...]
In the TypoScript, where the template is inserted:
10 = TEMPLATE
10 {
template = FILE
template.file = fileadmin/main.html
marks {
ID_SUFFIX = TEXT
ID_SUFFIX {
insertData = 1
# This makes sure that the output is valid and prevents XSS attacks
htmlSpecialChars = 1
value = {page:uid} # Use this to insert the page ID or
value = {page:subtitle} # Use to insert subtitle of page
... # Same works for other fields of the page record.
}
}
}
If the fields provided by default pages are not enough, you could add another field to the page records. The best way to do that would be to build an extension that does it.
I found a better solution, if i use ressource and add an image and on the next page do the same just with another images, then in my main TS i add this code.
lib.imageElement = FILES
lib.imageElement {
references {
data = levelmedia:-1,slide
listNum = 0
}
renderObj = COA
renderObj {
10 = IMAGE
10 {
file.import.data = file:current:originalUid
altText.data = file:current:title
}
}
}
It do the trick, then it shows a diffrent image in the top/header on every page.
But thx...

AS3: Getting values of objects by referencing their name

I'm reading XML and attaching values to objects in two seperate movieclips. Like this
Map01:
Marker01.name = hello there
Marker01.short = hel
Marker01.value = 12
Map02:
Marker02.name = hello there
Marker02.short = hel
Marker02.value = 99
Now I'm clicking on Marker01 in Map01 and get its name and value. I want to compare its value to that of Marker01 in Map02, using the name, or better yet .short because the names are long and use special characters/spaces. How do I do this? I've pretty much tried everything that seemed logical!
EDIT: sample code for clarification
var marker01:mc_marker = new mc_marker();
marker01.name="hello there";
marker01.short="abc";
marker01.val="99";
marker01.x=10;
marker01.y=10;
this.mc_map01.addChild(marker01);
var marker02:mc_marker = new mc_marker();
marker02.name="hello there";
marker02.short="abc";
marker02.val="20";
marker02.x=10;
marker02.y=10;
this.mc_map02.addChild(marker02);
marker01.addEventListener(MouseEvent.MOUSE_UP, showMarkerInfo);
marker02.addEventListener(MouseEvent.MOUSE_UP, showMarkerInfo);
function showMarkerInfo(event:MouseEvent):void {
txt_ms.text=event.target.short;
txt_mv.text=event.target.val;
if (event.target.short==mc_map02.marker02.short){
txt_mvi.text="here should be the marker02 value";
}
}
You have a typo there. Map02 use Marker1 things.
If its a typo in Stackoverflow,
this.getChildByName( "Marker01" ) will return you the movieclip, buy its name. take care though, as "name" is what it searches for. You used "hello there" when you should put Marker01 as the name. I would suggest you put a property called "data" and put the xml info in it so it doesn't conflict.
In the end you have:
if( this.getChildByName( "Marker01" ).data.value == this.getChildByName( "Marker02" ).data.value ).
I assume this is because you generate Marker0X at runtime and you can't declare some variables and use them directly.
Browny points if you make "data" a instance of a custom class where you can compare two "data". If you need more help, add a comment ^_^

Displaying Mediapicker field in blogpost.list.cshtml in Orchard CMS

I'm trying to edit the page when my blog displays the Parts.Blogs.BlogPost.List.cshtml. I went to ContentItems under content and added a MediaPicker Field called BlogPostImage to my BlogPosts, and I also made an alternate to Parts.Blogs.BlogPost.List.cshtml in my theme (which is the file I'm editing. The code that I have in there is:
#using Orchard.ContentManagement;
#{
IEnumerable<object> blogPosts =
Model.ContentItems;
}
#if (blogPosts == null || blogPosts.Count() < 1)
{
<p>#T("No posts.")</p>
}
else
{
int count = 0;
<div id="Blog">
<div id="slides">
<div class="slides_container">
#foreach (dynamic post in blogPosts)
{
count++;
string title = post.ContentItem.TitlePart.Title;
ContentItem item = post.ContentItem;
string text = post.ContentItem.BodyPart.Text;
string postImageUrl = post.BlogPostImage.Url;
<div class="slide">
<img src="#postImageUrl" width="625" height="400" alt="Slide #count.ToString()">
<div class="caption" style="bottom: 0">
<h4>#title</h4>
</div>
</div>
}
</div>
</div>
</div>
}
I cannot however figure out how in the world to call that mediapicker field into my list. Any way I try it comes back blank with some kind of querystring in the href. Something like "?23423455657". I took off the variable and that querystring still shows up. What I'm basically trying to accomplish is to put these into a slideshow, with the jquery to start the slideshow in the layout.cshtml. TIA
//SOLUTION:
After days and days of reading and researching I finally found a working solution.
Replacing:
string postImageUrl = post.BlogPostImage.Url;
With:
string postImageUrl = ((ContentItem)post.ContentItem).Parts.SelectMany(p => p.Fields).Where(f => f.Name == "BlogPostImage").First().Storage.Get<string>(null);
Got it from here: http://blog.cloudconstruct.com/post/Creating-a-rotating-image-gallery-in-Orchard-CMS.aspx
I hope it helps anyone stuck in the same boat. I am still curious why I couldn't simply call it the way I had it, but it's working now! :)
You can get the image url using dynamic:
dynamic postItem = post.ContentItem;
var postImageUrl = (string)postItem.BlogPost.BlogPostImage.Url;
Content item, when used as a dynamic object, exposes all its parts (here we're using the part that has the same name as the type, and where the fields are added when adding them from the admin). The part itself has dynamic members for each field (here, BlogPostImage), and from there you can get to the field's properties (Url here).
I tried the above answer with version 1.7 with no joy. I ended up having to download a copy of the source so I could delve into the objects. The below code got me the information I needed and also will help in future when I add extra fields to other content. I used part of the above answer to get to my solution...
IEnumerable<object> blogPosts = Model.ContentItems.ContentItems;
foreach (dynamic post in blogPosts) {
dynamic q = ((ContentItem)post.ContentItem).Parts.SelectMany(p => p.Fields).Where(f => f.Name == "BlogPostImage").First();
string postImageUrl = q.MediaParts[0].MediaUrl;
<img src="#postImageUrl" />
}
Hope this helps somebody.

Umbraco MediaById not working as expected

Trying to display a set of images from uComponents' MNTP, and can't get a value for the umbracoFile property - in the example below, both umbracoFile and url return empty strings:
foreach (var id in #Model.sliders) {
var media = Model.MediaById(id.InnerText);
if (media != null){
var url = media.umbracoFile;
<p>name = #media.Name</p>
<p>alt = #media.altText</p>
<p>url = #media.umbracoFile</p>
<p>url = #url</p>
}
}
It's getting really really really annoying... I've worked around it in other areas like so, using Model.Media:
<img src="#Model.Media("topRightImage", "umbracoFile")" alt="#Model.Media("topightImage", "altText")" />
But that will only help if with the media picker data type, not mntp. It shouldnt' be that difficult, should it?
I can get the images to load if I rebuild the internal search index, but they're gone again on subsequent refreshes.
I've seen others having similar problems, and would really appreciate a solution...
ta
Nathan
This looks like a bug that was fixed in 4.7.2. See the following codeplex item:
http://umbraco.codeplex.com/workitem/30778