Display inline

Talk about writing modules and plugins for CMS Made Simple, or about specific core functionality. This board is for PHP programmers that are contributing to CMSMS not for site developers
Post Reply
musicscore
Power Poster
Power Poster
Posts: 417
Joined: Wed Jan 25, 2006 11:53 am
Location: Netherlands

Display inline

Post by musicscore »

Hey you all.
My module is almost working as I planned but I'm facing one unsolved problem.

I have a php file pointing to a template :

Code: Select all

<?php

if( !defined('CMS_VERSION') ) exit;

$query = new CategoryQuery;
$categorys = $query->GetMatches();

$sql = 'SELECT SQL_CALC_FOUND_ROWS H.* FROM '.CMS_DB_PREFIX.'mod_msfaq_questions H WHERE category = "'.$params['cname'].'" ORDER BY question';
$arr = $db->GetArray($sql);

$tpl = $smarty->CreateTemplate($this->GetTemplateResource('default.tpl'),null,null,$smarty);
$tpl->assign('questions',$arr);
$tpl->assign('categorys',$categorys);
$tpl->display();

?>
The template looks like this :

Code: Select all

<div class="msfaq_wrapper">
template
	<div id="categoryBlock">
		{foreach $categorys as $category}
			<div class="category">
				<div class="row">
					<div class="categoryline"><a href="{cms_action_url action='default' cname=$category->category_name}">{$category->category_name}</a>
					</div>
				</div>
			</div> 
		{foreachelse}     
			<div class=”noquestions”>{$mod->Lang('noquestion')}</div>
		{/foreach}
	</div>
	
		<div id="questionAnswerBlock">
			{foreach from=$questions item=value}
			<div class="questionAnswer">
				<div class="question">{$value.question}</div>
				<div class="answer">{$value.answer}</div>
			</div>
		{/foreach} 
	</div>
</div>
Now I want to click on a category and the result must be displayed on the place of the tag on the page. (Inline I think this is called).
Now when I click on the

Code: Select all

<div class="categoryline"><a href="{cms_action_url action='default' cname=$category->category_name}">{$category->category_name}</a>
and the module tag is on a separate div on a page, an new section is opend.

What code do I need to put in the php file or template to replace the module tag and not create a new section?

Please help.

TIA
musicscore
Power Poster
Power Poster
Posts: 417
Joined: Wed Jan 25, 2006 11:53 am
Location: Netherlands

Re: Display inline

Post by musicscore »

Anyone ?

I'm building a module and want the replace the tag and not the page.

Please help

TIA
User avatar
Rolf
Dev Team Member
Dev Team Member
Posts: 7772
Joined: Wed Apr 23, 2008 7:53 am
Location: The Netherlands
Contact:

Re: Display inline

Post by Rolf »

Did you try:

Code: Select all

<a href="{cms_action_url action='default' cname=$category->category_name}&showtemplate=false">{$category->category_name}</a>
Image
- + - + - + - + - + -
Latest CMSMS tutorial: FormBuilder WatchGuard
- + - + - + - + - + -
Did my post help you solving a problem at your (customers) website and it saved you many hours of work?
Great!! Buy me a cup of coffee in return as a small token of appreciation!
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

Re: Display inline

Post by calguy1000 »

The {cms_action_url} plugin does not support creating inline URL's. You would have to use the create_url() method of the module API and pass in the inline flag and assign the output from that method to a smarty variable.

That said.. I would recommend that you not use inline mode unless absolutely necessary as inline URLS cannot be pretty. and, I have found that it is counter intuitive. When you click on a link you largely expect that the content you have selected will appear in the prominent area of the page, not a sidebar etc. And 99% of the time the {content} block should represent the location where the primary information is displayed.
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.
musicscore
Power Poster
Power Poster
Posts: 417
Joined: Wed Jan 25, 2006 11:53 am
Location: Netherlands

Re: Display inline

Post by musicscore »

Calguy1000

Thank you for your answer.

What I did was create a website where all the pages are displayed on one page. I used the tips on cmscanbesimple.org.
https://cmscanbesimple.org/blog/multipl ... query-tabs
I used the CGSimpleSmarty module as mentioned in the tip.

On one of the pages I want to use my module to display faq's.
Clicking on a category should display the questions in that category.

But when I click on a category the template replaces the content tag meaning the questions are not opened in the section where the category's are displayed.

You can see the problem on my test website
test.dev-infowebs.nl
Goto FAQ and click a category.

So I want the FAQ template to replace the faq-tag, not the content-tag

Please help
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

Re: Display inline

Post by calguy1000 »

Well, any link you generate will result in a page reload, and therefore a scroll. An inline link if you generated it properly using the create_url() method in the module API would generate the URL Properly, but would result in a page reload and a scroll.

In a single-page-app such as this you probably don't really want the thing to scroll every time you click something. I would just load the content via ajax. Which is pretty simple with jquery. The URL will not change, and there will be no scroll.

So if your category list template had:

<div id="mymodule">
{foreach $categories as $category}
<a href="{cms_action_url action='default' cname=$category->category_name}&showtemplate=false">{$category->category_name}</a>
{/foreach}
</div>

You could have a script section like (untested):
<__script__>
$(function(){
$('#mymodule a').click(function(ev){
ev.PreventDefault()
let href = $(this).attr('href')
$('#mymodule').load(href);
})
})
</__script>
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.
musicscore
Power Poster
Power Poster
Posts: 417
Joined: Wed Jan 25, 2006 11:53 am
Location: Netherlands

Re: Display inline

Post by musicscore »

Calguy1000

Thank you very much for this explanation.
I'm gonna try to use this jquery tip and let you know if was able to get it to work.
musicscore
Power Poster
Power Poster
Posts: 417
Joined: Wed Jan 25, 2006 11:53 am
Location: Netherlands

Re: Display inline

Post by musicscore »

I,m losing the battle. >:D

This is my template :

Code: Select all

<div class="msfaq_wrapper">

	<div id="categoryBlock">
		{foreach $categorys as $category}
			<div class="category">
				<div class="row">
					<div class="categoryline">
					<a href="{cms_action_url action='default' cname=$category->category_name}&showtemplate=false">{$category->category_name}</a>
					</div>
				</div>
			</div> 
		{foreachelse}     
			<div class=”noquestions”>{$mod->Lang('noquestion')}</div>
		{/foreach}
	</div>
	
	<div id="questionAnswerBlock">
				Question Answer Test
		{foreach from=$questions item=value}
			<div class="questionAnswer">
				<div class="question">{$value.question}</div>
				<div class="answer">{$value.answer}</div>
			</div>
		{/foreach} 
	</div>
</div>
And this is my php script :

Code: Select all

<?php

if( !defined('CMS_VERSION') ) exit;

$query = new CategoryQuery;
$categorys = $query->GetMatches();

$sql = 'SELECT SQL_CALC_FOUND_ROWS H.* FROM '.CMS_DB_PREFIX.'mod_msfaq_questions H WHERE category = "'.$params['cname'].'" ORDER BY question';
$arr = $db->GetArray($sql);

$tpl = $smarty->CreateTemplate($this->GetTemplateResource('default.tpl'),null,null,$smarty);
$tpl->assign('questions',$arr);
$tpl->assign('categorys',$categorys);
print_r($params);
$tpl->display();
?>
Here is my jquery script :

Code: Select all

$(function(){
	$('.categoryline a').click(function(ev){
	ev.PreventDefault();
	let href = $(this).attr('href');
	$('#faqmodule').load(href);
	})
})
When I click on a category, it opens a new page containing only the category's and the answers.

Test Here : http://test.dev-infowebs.nl/#faq

What is wrong in my code ?

I'm testing for over a week now, searching and searching what is wrong.

Please help.
User avatar
Rolf
Dev Team Member
Dev Team Member
Posts: 7772
Joined: Wed Apr 23, 2008 7:53 am
Location: The Netherlands
Contact:

Re: Display inline

Post by Rolf »

Looks to me your module *is* working, but it is a jQuery issue changing the content at that spot...

Great website by the way!!
Image
- + - + - + - + - + -
Latest CMSMS tutorial: FormBuilder WatchGuard
- + - + - + - + - + -
Did my post help you solving a problem at your (customers) website and it saved you many hours of work?
Great!! Buy me a cup of coffee in return as a small token of appreciation!
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3322
Joined: Mon Nov 28, 2011 9:29 am
Location: The Netherlands

Re: Display inline

Post by velden »

reload.js:

Code: Select all

$(function(){
	$('.categoryline a').click(function(ev){
	ev.preventDefault();
	let href = $(this).attr('href');
	$('#faqmodule').load(href);
	})
})
PreventDefault vs. preventDefault.
musicscore
Power Poster
Power Poster
Posts: 417
Joined: Wed Jan 25, 2006 11:53 am
Location: Netherlands

Re: Display inline

Post by musicscore »

Thank you Calguy1000 en Velden.

I got it working :

To help others, here is my code :

action.default.php

Code: Select all

<?php

if( !defined('CMS_VERSION') ) exit;

$query = new CategoryQuery;
$categorys = $query->GetMatches();

$sql = 'SELECT SQL_CALC_FOUND_ROWS H.* FROM '.CMS_DB_PREFIX.'mod_msfaq_questions H WHERE category = "'.$params['cname'].'" ORDER BY question';
$arr = $db->GetArray($sql);

$tpl = $smarty->CreateTemplate($this->GetTemplateResource('default.tpl'),null,null,$smarty);
	
$tpl->assign('questions',$arr);
$tpl->assign('categorys',$categorys);
$tpl->display();

?>
default.tpl

Code: Select all

<div class="msfaq_wrapper">

	<div id="categoryBlock">
		{foreach $categorys as $category}
			<div class="category">
				<div class="row">
					<div class="categoryline">
					<a href="{cms_action_url action='default' cname=$category->category_name}&showtemplate=false">{$category->category_name}</a>
					</div>
				</div>
			</div> 
		{foreachelse}     
			<div class=”noquestions”>{$mod->Lang('noquestion')}</div>
		{/foreach}
	</div>
	
	<div id="questionAnswerBlock">
				Question Answer Test
		{foreach from=$questions item=value}
			<div class="questionAnswer">
				<div class="question">{$value.question}</div>
				<div class="answer">{$value.answer}</div>
			</div>
		{/foreach} 
	</div>
</div>

<__script__ src="assets/scripts/reload.js"></__script>
reload.js

Code: Select all

$(function(){
	$('.categoryline a').click(function(ev){
	ev.preventDefault();
	let href = $(this).attr('href');
	$('#faqmodule').load(href); 
	})
})
Thank you guys. You are the best and you saved my day.
musicscore
Power Poster
Power Poster
Posts: 417
Joined: Wed Jan 25, 2006 11:53 am
Location: Netherlands

[Solved] Display inline

Post by musicscore »

It's working
Post Reply

Return to “Developers Discussion”