Create dropdownfield in backend to select a page / link

The place to talk about things that are related to CMS Made simple, but don't fit anywhere else.
Post Reply
Menno
New Member
New Member
Posts: 4
Joined: Fri Oct 15, 2010 2:45 pm

Create dropdownfield in backend to select a page / link

Post by Menno »

Hi you all,

I'm searching for a solution to create a dropdown list white all the pages on the site.
This because I want to give the customer the possibility to select which page an image refers to.

In example I would like to add to my template . I hope this is possible without using the advanced content module.

version: 1.8.2

Hope one of you can help me  :)
User avatar
Dr.CSS
Moderator
Moderator
Posts: 12711
Joined: Thu Mar 09, 2006 5:32 am

Re: Create dropdownfield in backend to select a page / link

Post by Dr.CSS »

Add an image in tiny, click the image then use the self link to add a link to the page you want...
Menno
New Member
New Member
Posts: 4
Joined: Fri Oct 15, 2010 2:45 pm

Re: Create dropdownfield in backend to select a page / link

Post by Menno »

I'm sorry I wasn't very clear in my question.

The thing is on each page I have 2 or 3 small blocks which contains a title, image, text and a read more image.

I would like to create a dropdownform where the user can select the page for the link so all of the three parts (title, image and read more image) refers to that page.

In the template I all ready have this:
{content block="inhoud_link" oneline="true" assign="inhoud_link"}
and on those three items I use

So the customer needs to fill in the alias which can result in an error if he doesn't use the right alias.

Thanx again:)
NaN

Re: Create dropdownfield in backend to select a page / link

Post by NaN »

Sorry, but I don't know a way without using AdvancedContent module.
landarone
Forum Members
Forum Members
Posts: 23
Joined: Tue Jun 24, 2014 9:24 pm

Re: Create dropdownfield in backend to select a page / link

Post by landarone »

Hello there.
I know this is old topic but it is now what I would like to solve.
Could anyone give me some advice how to do it please?

I mean to create a dropdown where the user (in backend) can select the page name from all existed/created pages.
This dropdown should display list of pages and return alias of selected one (because I need to get the link from it and use this for another part of my template).

I know how to add "dropdown block" with AdvancedContent, but I didnt find what code I should give into "item" and "values".
Some UDT or Smarty or SimpleSmarty code?

Thank you so much :)
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3497
Joined: Mon Nov 28, 2011 9:29 am

Re: Create dropdownfield in backend to select a page / link

Post by velden »

This code I use on one of my sites.
It needs module 'ECB'

Code: Select all

{content_module module="ECB" field="pages" label="Actie-pagina" block="actie-page" assign='actiepage'}
{capture name="ap" assign="actiename"}{cms_selflink page=$actiepage}{/capture}
{if $actiename}			   
			   <div id="header-block-bottom">
			     <h1>Actie</h1>
				 <h1 id="actie-title">{$actiename|strip_tags}</h1>
				 <a href="{cms_selflink href=$actiepage}">>> vertel mij er alles over</a>
			   </div>
{/if}
I'm sure there is a neater way to retrieve title/menu text of target page, but it does the job.
chandra

Re: Create dropdownfield in backend to select a page / link

Post by chandra »

@Velden

You don't need an additional capture for cms_selflink. Has an assign param itself ;).
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3497
Joined: Mon Nov 28, 2011 9:29 am

Re: Create dropdownfield in backend to select a page / link

Post by velden »

Good point. I realize it's not most efficient code nor best example.

But I don't tend to change my code while job is done.

Feel free to optimize the example code.
chandra

Re: Create dropdownfield in backend to select a page / link

Post by chandra »

Do what you want. But you should know that every additional Smarty command needs some (more) time to be done.

Yeah someone could say it makes no difference if website will be 0.1 seconds faster. Really?

Let's make an example. Say website has currently 100 visitors what's not a really high value. So you can see now the difference is 10 seconds ;).

Long speech short sense - want only focus your eyes to an efficient coding ;).
landarone
Forum Members
Forum Members
Posts: 23
Joined: Tue Jun 24, 2014 9:24 pm

Re: Create dropdownfield in backend to select a page / link

Post by landarone »

Hello there.
Thanks everyone for help.
I was trying to do it by myself and finally I found solution, in 2 clock in the morning :)
I use two UDT codes (SQL query in DB), one for names and one for aliases.
These results I give into "items" and "values" for block_type="dropdown". So user can select right page with right URL in backend.
It is for boxes (DIVs) url and these boxes have Title + some text and small image in background. So it looks like an clickable tile. And these tiles you can completely managed in CMS template.

I dont know how much time tooks querry and code rendering in backend and also in frontend but for me it is not slow. I can say that I expect maximum 50 users in one moment and in these days of internet speed conection I dont think it will be too slow for anyone. But Im only man.... :)

Here is UDT code for names

Code: Select all

//UDT tag name is {all_pages_names}
$db = cmsms()->GetDb();      
$query = "SELECT (content_name) FROM " . cms_db_prefix() . "content WHERE type='content' ORDER BY content_id";
$result = $db->Execute($query);
$row = $result->GetRows();

if ($result) {
  foreach($row as $key => $value)
  {
    echo $value['content_name'] . " | ";
  }
} else {
  echo 'query failed';  
}
Here is UDT code for aliases

Code: Select all

//UDT tag name is {all_pages_names}
$db = cmsms()->GetDb();      
$query = "SELECT (content_alias) FROM " . cms_db_prefix() . "content WHERE type='content' ORDER BY content_id";
$result = $db->Execute($query);
$row = $result->GetRows();

if ($result) {
  foreach($row as $key => $value)
  {
    echo $value['content_alias'] . " | ";
  }
} else {
  echo 'query failed';  
}
Maybe it help someone for another codeing :)
Im not sure if these codes are "right way" and not so dirty, maybe some of you know better and clearly code, but it work on 100% :)
uniqu3

Re: Create dropdownfield in backend to select a page / link

Post by uniqu3 »

You could as well use "Extende Content Blocks" module that comes with "Content pages" dropdown built in.

http://dev.cmsmadesimple.org/projects/econtentblocks

From module help
pages
Example: {content_module module="ECB" field="pages" label="Page" block="test10"}
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm

Re: Create dropdownfield in backend to select a page / link

Post by calguy1000 »

CGContentUtils has a page selector block type as well.
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
Post Reply

Return to “The Lounge”