We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 17035
    • 36 Posts
    Hi All,

    I've been working on a website based from a template purchased on Template Monster - http://www.templatemonster.com/demo/39222.html

    As you'll see when clicking on the menu links, new content is pulled in from the left hand side. When purchasing the template, I can see that this works basically as a list. For example:

    There is a menu:

    <ul class="sf-menu">
    					<li class="menu1"><a href="#!/about">about us</a></li>
    					<li class="menu2"><a href="#!/catalogue">catalogue</a></li>
    					<li class="menu3"><a href="#!/join">join us</a></li>
    					<li class="menu4"><a href="#!/articles">articles</a></li>
    					<li class="menu5"><a href="#!/locations">locations</a></li>
    				</ul>
    


    When the items are clicked above, it pulls in the relevant <li> tag from the <section id="content"> below.

    eg:

    <li id="about">
    					<div class="main">
    						<div class="shadow2">
    							<h1 class="logo"><a href="#!/about">Hip Hop</a></h1>
    							<div class="content">
    								<div class="text1">
    									<p>Fusce feugiat maluadas orb nae feugi luorbilorer keroa as nae dedskertsdefer lerose merro orbraesrto mertasedears selertdaker tsdefer lerose merrose kertase.</p>
    									<div class=""><a href="#!/more">Join Us!</a></div>
    								</div>
    								<div class="wrapper pad">
    									<div class="col1">
    										<h2>testimonials</h2>
    										<blockquote class="quote"><a href="#">Karina Smith</a><br>
    										Mery lecenas stricies phaleda
    										tyfenanec sit amm easer erment. 
    										Ut ts dolor dapege telementum.</blockquote>
    										<div class="box-button"><a href="#!/more" class="button">Read More</a></div>
    									</div>
    									<div class="col2">
    										<h2>dance classes</h2>
    										<div class="fleft"><ul class="list1">
    											<li><a href="#">Andrew Cesan</a></li>
    											<li><a href="#">Richie Cesan</a></li>
    											<li><a href="#">Ginny Crocker</a></li>
    											<li><a href="#">Catherine Hancox</a></li>
    											<li><a href="#">Simon Watts</a></li>
    										</ul></div>
    										<div class="fleft"><ul class="list1">
    											<li><a href="#">david Jones</a></li>
    											<li><a href="#">Peter Kemble</a></li>
    											<li><a href="#">Sharnika Robson</a></li>
    											<li><a href="#">Melanie Staple</a></li>
    											<li><a href="#">Patrick Svenson</a></li>
    										</ul></div>
    									</div>
    								</div>
    							</div>
    						</div>
    						<span class="shadow"></span>
    					</div>
    				</li>
    


    All the JS is in separate script files.

    What I've done so far is as follows:

    1) Uploaded the template in full to a template file and added in the base href tag.

    2) Sorted out the directories so that they match and the template works as it did on template monster (can click between the pages and it works as it should).

    3) Split the header section out into it's own chunk

    4) Taken all of the 'li id's' out and copied each of these sections into separate resources. Then added in the [[*content]] tag to the main template.

    5) Enabled SEO friendly URL's so that the resource names match the URL string and updated the menu so that it shows as (as an example):

    <a href="#!/[[~2]]">About Us</a>


    6) Removed the .html extension by going into Modx revolution and removing this in Content Types


    Now, when you click on any of the links, they look correct, but it's not loading in the content from the external resources.

    I don't personally have a lot of experience with AJAX so any help you can give me would be really appreciated! The site can be seen at www.freestyle-education.co.uk You'll notice that when it loads, if you click on 'Home', it does pull in a page. This is pulling in from the main template and the home resource that is the main one when the page loads (if that makes sense). None of the other pages work even though they match the li's.

    Hopefully the above makes sense! I'd really appreciate any advice anyone is able to give!!

    Kind regards,
    Lewis
      • 4172
      • 5,888 Posts
      can't see anything, what has todo something with Ajax.

      On the demo - site there are all sections loaded at once.

      On your site there is only the home-section as the only li in the ul-list.
      Does this script has an ajax-option, which loads the sections, when they are needed by an ajax-request?


        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 17035
        • 36 Posts
        Hey,

        Thanks for the reply!

        I've removed out all of the additional li's out of the ul-list into separate resources.

        What I want to achieve, is that MODx will call in the relevant resource (which is the whole of the centre content section) when the tabs are clicked along the top.

        My main template is now as follows:

        [[$header]]
        		<section id="content">
        			<ul>
                                     [[*content]]
        	                </ul>
        		</section>
        		
        <footer>
        			<div>Freestyle Education © 2012 • <a href="#!/privacy">Privacy Policy</a> • Development by <a href="http://www.pinpointdesigns.co.uk">Pinpoint Designs</a></div>
        			<ul class="social">
        				<li><a href="#"><img src="assets/freestyle/images/icon1.png" alt="Facebook"></a></li>
        				<li><a href="#"><img src="assets/freestyle/images/icon2.png" alt="Twitter"></a></li>
        			</ul>
        		</footer>
        	</div>
        
        <script type="text/javascript">
                var DISModifyPost = $(function() {
                    DIS.config.attachments_max_per_post = 5;
                    DIS.DISModifyPost.init({
                        attachments: 1
                    });
                });</script>
        </body>
        </html>
        


        Obviously, when you visit the site, 'Home' is working as that's pulling in the following information from the resource ID 1.

        <li id="home">
        					<div class="main">
        						<div class="shadow2">
        							<h1 class="logo"><a href="#!/home">Hip Hop</a></h1>
        							<div class="content">
        								<div class="pad2">
        									<h2>our catalogue</h2>
        									<ul class="list2">
        										<li><a href="#">
        											<img src="assets/freestyle/images/2page_img1.png" alt="">
        									
        											<span class="color2">15.05.2012</span>
        
        											Mery lecenas striciesn.
        										</a></li>
        										<li><a href="#">
        											<img src="assets/freestyle/images/2page_img2.png" alt="">
        								
        											<span class="color2">18.05.2012</span>
        
        											Mery lecenas striciesn.
        										</a></li>
        										<li><a href="#">
        											<img src="assets/freestyle/images/2page_img3.png" alt="">
        									
        											<span class="color2">20.05.2012</span>
        
        											Mery lecenas striciesn.
        										</a></li>
        										<li><a href="#">
        											<img src="assets/freestyle/images/2page_img4.png" alt="">
        									
        											<span class="color2">23.05.2012</span>
        
        											Mery lecenas striciesn.
        										</a></li>
        										<li><a href="#">
        											<img src="assets/freestyle/images/2page_img5.png" alt="">
        									
        											<span class="color2">25.05.2012</span>
        
        											Mery lecenas striciesn.
        										</a></li>
        										<li><a href="#">
        											<img src="assets/freestyle/images/2page_img6.png" alt="">
        									
        											<span class="color2">30.05.2012</span>
        
        											Mery lecenas striciesn.
        										</a></li>
        									</ul>
        								</div>
        							</div>
        						</div>
        						<span class="shadow"></span>
        					</div>
        				</li>


        However, what I want to achieve, is that when someone clicks on 'Dance' (Resource ID 2), it loads in the following instead:

        <li id="dance">
        					<div class="main">
        						<div class="shadow2">
        							<h1 class="logo"><a href="#!/dance">Hip Hop</a></h1>
        							<div class="content">
        								<div class="pad2">
        									<h2>our catalogue</h2>
        									<ul class="list2">
        										<li><a href="#">
        											<img src="assets/freestyle/images/2page_img1.png" alt="">
        									
        											<span class="color2">15.05.2012</span>
        
        											Mery lecenas striciesn.
        										</a></li>
        										<li><a href="#">
        											<img src="assets/freestyle/images/2page_img2.png" alt="">
        								
        											<span class="color2">18.05.2012</span>
        
        											Mery lecenas striciesn.
        										</a></li>
        										<li><a href="#">
        											<img src="assets/freestyle/images/2page_img3.png" alt="">
        									
        											<span class="color2">20.05.2012</span>
        
        											Mery lecenas striciesn.
        										</a></li>
        										<li><a href="#">
        											<img src="assets/freestyle/images/2page_img4.png" alt="">
        									
        											<span class="color2">23.05.2012</span>
        
        											Mery lecenas striciesn.
        										</a></li>
        										<li><a href="#">
        											<img src="assets/freestyle/images/2page_img5.png" alt="">
        									
        											<span class="color2">25.05.2012</span>
        
        											Mery lecenas striciesn.
        										</a></li>
        										<li><a href="#">
        											<img src="assets/freestyle/images/2page_img6.png" alt="">
        									
        											<span class="color2">30.05.2012</span>
        
        											Mery lecenas striciesn.
        										</a></li>
        									</ul>
        								</div>
        							</div>
        						</div>
        						<span class="shadow"></span>
        					</div>
        				</li>


        I don't want the page to reload, so I'm going to have to use AJAX to load the additional resource and pull it through. The original theme is obviously setup with JQuery to slide the new content in so that's what I'm trying to achieve..

        Hopefully that makes sense? Any help on this would be great!

        Kind regards,
        Lewis [ed. note: LewisSellers last edited this post 13 years, 11 months ago.]
          • 17035
          • 36 Posts
          Hey guys,

          Just wondered if anyone has any tips on how I can implement this functionality using MODx? Getting really stumped with this and would appreciate any help anyone is able to give!

          Is it even possible to use different resources and load them in via AJAX on MODx? Or am I better just creating Template variables and having all the pages within one resource with Template variables for the client to update things?

          I wanted to avoid that as to me, that would be a bit sloppy, but if that's the only option, then I'll have to look at that route.

          Many thanks,
          Lewis
            • 28042 ☆ A M B ☆
            • 24,524 Posts
            MODx doesn't care what javascript or AJAX you use. I would have the resources you want to insert be ordinary resources with empty templates. Then you can use a very simple AJAX library like JQuery's load() function giving the desired resource as the URL for the request.
              Studying MODX in the desert - http://sottwell.com
              Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
              Join the Slack Community - http://modx.org
              • 17035
              • 36 Posts
              Quote from: sottwell at Oct 18, 2012, 06:23 AM
              MODx doesn't care what javascript or AJAX you use. I would have the resources you want to insert be ordinary resources with empty templates. Then you can use a very simple AJAX library like JQuery's load() function giving the desired resource as the URL for the request.

              Hi Susan,

              Thanks for the response.

              Ok, I've setup two templates:

              1) Blank Template (completely empty inside)
              2) Main Template (This includes all of the layout, but I've taken out all of the li tags and replaced this with a [[*content]] tag.

              My homepage resources (ID 1) had the 'Main Template' assigned to it. Within this, It's got the following code:

              <li id="home">
              					<div class="main">
              						<div class="shadow2">
              							<h1 class="logo"><a href="#!/home">Hip Hop</a></h1>
              							<div class="content">
              								<div class="pad2">
              									<h2>our catalogue</h2>
              									<ul class="list2">
              										<li><a href="#">
              											<img src="assets/freestyle/images/2page_img1.png" alt=""><br>									
              											<span class="color2">15.05.2012</span><br>
              											Mery lecenas striciesn.
              										</a></li>
              										<li><a href="#">
              											<img src="assets/freestyle/images/2page_img2.png" alt=""><br>								
              											<span class="color2">18.05.2012</span><br>
              											Mery lecenas striciesn.
              										</a></li>
              										<li><a href="#">
              											<img src="assets/freestyle/images/2page_img3.png" alt=""><br>									
              											<span class="color2">20.05.2012</span><br>
              											Mery lecenas striciesn.
              										</a></li>
              										<li><a href="#">
              											<img src="assets/freestyle/images/2page_img4.png" alt=""><br>									
              											<span class="color2">23.05.2012</span><br>
              											Mery lecenas striciesn.
              										</a></li>
              										<li><a href="#">
              											<img src="assets/freestyle/images/2page_img5.png" alt=""><br>									
              											<span class="color2">25.05.2012</span><br>
              											Mery lecenas striciesn.
              										</a></li>
              										<li><a href="#">
              											<img src="assets/freestyle/images/2page_img6.png" alt=""><br>									
              											<span class="color2">30.05.2012</span><br>
              											Mery lecenas striciesn.
              										</a></li>
              									</ul>
              								</div>
              							</div>
              						</div>
              						<span class="shadow"></span>
              					</div>
              				</li>


              The menu is then setup as:

              <div class="main-menu">
              				<ul class="sf-menu">
              					<li class="menu1"><a href="[[~1]]">Home</a></li>
              					<li class="menu2"><a href="[[~2]]">Dance</a></li>
              					<li class="menu3"><a href="[[~3]]">Music</a></li>
              					<li class="menu4"><a href="[[~4]]">Drama</a></li>
              					<li class="menu5"><a href="[[~5]]">Media</a></li>
              					<li class="menu6"><a href="[[~6]]">Consultation</a></li>
              					<li class="menu7"><a href="[[~7]]">About Us</a></li>
              					<li class="menu8"><a href="[[~8]]">Contact Us</a></li>
              				</ul>
              			</div>



              There is a file called script.js which contains the 'page sliding' section to pull in the additional content. The code contained is as follows:

              $('#loading').show();
              
              $(function(){
              	jQuery('.bg1').parallax({yparallax:false, xparallax: '30px'});
              	jQuery('.bg2').parallax({yparallax:'10px', xparallax: '20px'});
              	jQuery('.bg3').parallax({yparallax:'20px', xparallax:false});
              	jQuery('.bg3-2').parallax({yparallax:'10px', xparallax:false});
              	
              	$('.social li a img').css({opacity:.3});
              	$('.social li a').hover(function(){$(this).find('img').stop().animate({opacity:1})},(function(){$(this).find('img').stop().animate({opacity:.3})}));
              	
              	var content = $('#content');
              		content.tabs({
              			show:0,
              			preFu:function(_){
              			   _.li.css({'display':'none'})			
              			},
              			actFu:function(_){        
              				if(_.curr){
              					
              					_.curr
              						.css({'left':'-2000px'}).stop(true).show().animate({'left':'0'},{duration:600,easing:'easeInOutExpo'});
              				}   
              				if(_.prev){
              					_.prev
              						.show().stop(true).animate({'left':'2000px'},{duration:600,easing:'easeInOutExpo',complete:function(){
              								if (_.prev){
              									_.prev.css({'display':'none'});
              								}
              							}
              						  });
              				}        
              			}
              		});
              	
              		var nav = $('.main-menu');
              		nav.navs({
              			useHash:true,
              			defHash:'#!/about'
              		})
              		.navs(function(n){	
              			$('#content').tabs(n);
              		});
              });
              
              
              $(window).load(function(){
              	$('#loading').hide();
              });


              I'm assuming I need to alter this code to pull in the resources, but I'm not really sure how I go about doing this? It's a separate JS file outside of MODx, so do I pull it into the actual template and add in a couple of variables to pull in the right section?

              Sorry for all the questions. Any help you can provide is always appreciated!!

              Kind regards,
              Lewis
                • 28042 ☆ A M B ☆
                • 24,524 Posts
                Sorry, I'm kind of overloaded with stuff right now, and am not much good for anything except generalities. I don't really understand what is is all the javascript is doing. I was thinking along the lines of something like
                $('#maincontent').load('page.html');

                This would fetch page.html, which would get processed and served by MODx like any page request, and then get loaded into your "mainconent" div.
                  Studying MODX in the desert - http://sottwell.com
                  Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                  Join the Slack Community - http://modx.org
                  • 17035
                  • 36 Posts
                  Quote from: sottwell at Oct 18, 2012, 08:20 AM
                  Sorry, I'm kind of overloaded with stuff right now, and am not much good for anything except generalities. I don't really understand what is is all the javascript is doing. I was thinking along the lines of something like
                  $('#maincontent').load('page.html');

                  This would fetch page.html, which would get processed and served by MODx like any page request, and then get loaded into your "mainconent" div.

                  Thanks for your reply.

                  Looking at the JQuery, the top part is all to do with the Parallax scrolling effect that is going on in the background. Theres a couple of little animation bits for the social media icons on the page.

                  Moving further down, the #content section is because when you click one of the tabs, the new content is loaded in and it slides across the page. So I believe this part is just the animation part.

                  The bit I need to be looking at (I think) is this part:

                   var nav = $('.main-menu');
                          nav.navs({
                              useHash:true,
                              defHash:'#!/about'
                          })
                          .navs(function(n){  
                              $('#content').tabs(n);
                          });


                  Am I correct in thinking that the homepage (resource ID 1) would have the main template though? And then within that, I'd pull in this JS, and do something along the lines of what you recommended, where "page.html" would be substituted with the resource ID? Or am I misunderstanding you?

                  I think I may need someone to outsource this section of work too... I think I understand what you mean, but I'm having trouble getting my head around how I get MODx to use it in relation to the different resources...

                  Kind regards,
                  Lewis
                    • 28042 ☆ A M B ☆
                    • 24,524 Posts
                    I think you have it right. The load() function just needs to be fed the URL to the resource whose content you want loaded. Remember, an AJAX request is really no different than any browser's page request. The server and MODx don't care, they just process the request like they do any other HTTP request. The trick in this case is that the URL being requested will not be a full web page, just the content of the resource being requested, since it has no template. So MODx will simply process the content of the resource and pass it on to the server, who will return it as usual. The Javascript in the browser will simply load what it is given into the div you tell it to. It's really very simple. The trick will be to make the URL variable, dependent on which tab or button or link was clicked to trigger the AJAX request.

                    http://www.ajaxblender.com/howto-create-custom-jquery-tabs.html

                    Notice in the loadTab() function

                    $(containerId).load(tabObj.attr('href'), function(){ ... 


                    This determines the URL from the href attribute of the tab (styled link) that was clicked. All the rest of the javascript is just eye candy; the heart of the thing is in this load() function.
                      Studying MODX in the desert - http://sottwell.com
                      Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                      Join the Slack Community - http://modx.org
                      • 17035
                      • 36 Posts
                      Quote from: sottwell at Oct 18, 2012, 10:03 AM
                      I think you have it right. The load() function just needs to be fed the URL to the resource whose content you want loaded. Remember, an AJAX request is really no different than any browser's page request. The server and MODx don't care, they just process the request like they do any other HTTP request. The trick in this case is that the URL being requested will not be a full web page, just the content of the resource being requested, since it has no template. So MODx will simply process the content of the resource and pass it on to the server, who will return it as usual. The Javascript in the browser will simply load what it is given into the div you tell it to. It's really very simple. The trick will be to make the URL variable, dependent on which tab or button or link was clicked to trigger the AJAX request.

                      http://www.ajaxblender.com/howto-create-custom-jquery-tabs.html

                      Notice in the loadTab() function

                      $(containerId).load(tabObj.attr('href'), function(){ ... 


                      This determines the URL from the href attribute of the tab (styled link) that was clicked. All the rest of the javascript is just eye candy; the heart of the thing is in this load() function.

                      Hi Susan,

                      Thanks for all your help on this! I'll have a play around and post my findings once I hopefully get it all working!

                      Thanks once again, really appreciate it.

                      Kind regards,
                      Lewis