How can I use base_path() inside a view in Drupal? - drupal-6

I have the following fields inside a view:
User ID
Teaser
I selected "exclude from display" for the User ID field.
In the Teaser field, I selected the "rewrite the output of this field" option. This way, I can use html to completely control the structure of the view's output. Moreover, I can call the User ID field by using it's token, [uid].
For example, I can do the following in the teaser's rewrite:
Visit Profile
The problem with the above code is that the path is relative. It will only work on the front page of the site.
For example, if this link is clicked in
www.example.com/node/1
then it will visit a non-existent URL of:
node/1/user/[uid]
I have tried the following: http://chopapp.com/#o7osql65
But views fields does not allow PHP codes.
I might be approaching this entirely wrong. Does anyone have any suggestions? Thanks.

You'll want to rewrite the output of the UID field, and have it be rendered as a link. Even if you exclude it from display initially, it will still be available as a link via its token to other fields. One of the options when selecting to 'output this field as a link' is to make the link absolute.

Related

Template to provide static HTML wrapping a page-specific value

I am creating a page template. Each page using the template will have a single unique value that gets embedded into the page HTML. The rest of the HTML is constant for all pages. Assume the following is the desired result:
click me
I want a template that provides click me, while allowing the individual pages (content admins) to provide id.
I've tried using an Editable Text web part, and putting the "before" and "after" HTML in the HTML Envelope before and after sections, and adding the ID on the "Page" tab. However, that is not quite working. What is the best way to accomplish this?
This can be done. What you'd want to do is add that field to the page type fields you're adding those pages with. For instance, say you have a list of locations under /locations.
i.e.:
/location/chicago
/location/new-york
/location/minneapolis
The locations themselves (Chicago, New York, Minneapolis) are your custom page type and have a unique field called LocationID. On your template, add a static text webpart (not static HTML because the WYSIWYG editor overwrites the markup you add) and simply add this:
click me
If the LocationID field has a exists AND has a value, it will output it, otherwise it will just leave the URL http://www.example.com/
If you didn't want to show that link at all on other pages, then set the Show for page types property based on the page type you want it to show for in the Visibility section of the static text webpart.

XPages Mobile Controls - sessionScope variable being lost

I am building a mobile app for iPhone using the mobile controls in the XPages Extension Library.
The first page displays a list of categories (happens to be a list of user names). When a category is selected the second page is displayed listing all documents belonging to the selected user.
The URL to open the second page includes a parameter with the user's name. The second page has a page heading control and on the "label" property I have added the following code:-
if (param.get("User") != null) {
sessionScope.put("UserName", param.get("User"));
}
return sessionScope.UserName;
I'm doing this so that I have access to the user name on subsequent pages, e.g. the third page is displayed when the user opens a document from the list on the second page.
When I test this in Chrome everything is fine. When I test in Safari I can see that the sessionScope variable is set when the second page is opened. However, when I select a document and the third page is opened the sessionScope variable is disappearing. I can't see any code that would explain this and when tested in Chrome the sessionScope variable is still there on page 3. Unsurprisingly I get the same issue when I test on an iPhone.
The problem this gives me is that, when navigating back from a document (p.3) to the list of documents for the selected user (p.2) I don't know which user was selected originally.
Anyone seen this before or have any explanation as to what might be going on?
Thanks for any suggestions.
you might want to refrain from the parameter approach unless you are sanetizing your input first, so instead of the URL write the userName directly into the scope - or even easier - bind the first field with the categories to the sessionScope. Did u try to modify your code to use a different variable name?

How to show list of custom objects in a page in Drupal

I want to create a page in Drupal 6 where I can show list of restaurants.When a user clicks on any restaurant page, I should be redirected to Restaurant details page.
For this :
1.) I created a new content type called "Restaurant" with some fields.
2.) Created 3-4 content items for Restaurant( Restaurant1, Restaurant2, Restaurant3)
3.) Created view called: RestaurantList, Added Fields for it. Then added Page Display and gave the path for it http://website/Restaurants
Now, when I browse to Restaurants page, I only get labels of my fields but no values. How can I get the values but not the labels? Also, I want to go to the RestaurantDetails page. How can that be achieved?
Thanks,
Rashmi
Well if I were to set up a page view this is how I would set it up:
Filters:
Node type - Restaurants
Node published - Yes
Fields
Node title
check the option Link this field to it's node
leave the Label: field empty
check option Hide if empty
And if your view style is a HTML list, for extra you can go to Row style options and check the option: Hide empty fields
Make sure you click Preview to see if you get any values. If you don't then there's something wrong with the view settings, most probably the filters which are to restrictive. Start with something loose, like Node type - Restaurants.

change layout content from controller

I am using Yii. I want to have a dynamic link on a layout. This dynamic link will be modified by controllers. Let's say that dynamic link uses a user's id given by controllers to perform a task.
I am thinking to use jQuery script to get user id returned by controllers then use the user id to modify a div that holds the dynamic link.
What do you think about this technique?
It seems like you want to dynamically change a link AFTER the page is rendered, with client-side JavaScript. But it makes more sense to dynamically render a different link the first time, during the server-size PHP rendering process. The controller generates the view, after all! I would get the user ID from the controller during the page request, pass the ID in to the view, and then build the link in the view dynamically on the initial page load.
If you are modifying a link in a layout (not a view), then the best thing to do is create a variable in the Controller, and set that variable with the view. Look at how Yii uses the $layout, $menu and $breadcrumbs variables to do this.
Assuming that the user is logged in and you want their ID, you can get the ID from the Yii::app() object as well, like so:
<?php echo CHtml::link('Edit user',array('user/edit','userId'=>Yii::app()->user->id)); ?>
But at that point, you can just request the user's ID in the controller, and don't need to build a link like this.
Assuming that you want a different user ID than the logged in user, pass that ID ($userId) from the controller into the view, and just do this (as Moyersy said):
<?php echo CHtml::link('Edit user',array('user/edit','userId'=>$userId)); ?>
This will build the following link (where $userId = 99999999):
Edit user
So when the linked is clicked, in the actionEdit() you now have access to the user's ID via the GET variable $_GET['userId'].
NOW, if what you want to do is change an already created link, then you would need to use jQuery. But you will need to explain in more detail why you are doing this and what is triggering the link change (a dropdown menu?).
I'm sorry, I can't understand what you are trying to do. Specifically I don't understand what a dynamic link is.
Edit:
<? echo CHtml::link('Edit user',array('user/edit','userId'=>$userId)); ?>

Change the action when clicking on a list item

I would like to change the destination URL when clicking on a list item / item title so it will no send me to view the item but will send me to a different URL base on the item.
I am not looking to replace the Links list but to use the list title as URL query filter.
Thanks
You will need to do it using the custom Page / Customize the View Page in the SharePoint Designed. Please refer to this article on how you can achieve it using the SPGridView control
I'm not totally clear on what you'd like to do (maybe screenshot mock ups would help?), but here's some general advice.
If you want to change the behaviour of a control then investigate the properties of the control as kusek has suggested. If the properties don't do what you need then try overriding the control to change what is rendered.
If the above doesn't work out or you want to change how these links render no matter where they appear on the page, then you need to look at a page-level solution. The most common are jQuery that can dynamically replace the URLs with JavaScript, or an HTTP module which is much more low level and will actually alter the HTML rendered to the page.
Hope this helps.

Resources