Page 1 of 1

Create dropdownfield in backend to select a page / link

Posted: Fri Oct 15, 2010 2:57 pm
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Ā  :)

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

Posted: Fri Oct 15, 2010 3:46 pm
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...

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

Posted: Mon Oct 18, 2010 9:56 am
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:)

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

Posted: Wed Oct 20, 2010 5:39 pm
by NaN
Sorry, but I don't know a way without using AdvancedContent module.

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

Posted: Tue Jun 24, 2014 9:55 pm
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 :)

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

Posted: Wed Jun 25, 2014 9:20 am
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.

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

Posted: Wed Jun 25, 2014 9:32 am
by chandra
@Velden

You don't need an additional capture for cms_selflink. Has an assign param itself ;).

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

Posted: Wed Jun 25, 2014 9:44 am
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.

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

Posted: Wed Jun 25, 2014 7:31 pm
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 ;).

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

Posted: Wed Jun 25, 2014 10:03 pm
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% :)

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

Posted: Thu Jun 26, 2014 8:16 am
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"}

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

Posted: Thu Jun 26, 2014 2:03 pm
by calguy1000
CGContentUtils has a page selector block type as well.