Nov 21, 2008, 08:05 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
Search via SMF or Google: modx forums all of modxcms.com web
  MODxCMS.com   Forums   Help Login Register  
Pages: [1] 2 3   Go Down
  Print  
Author Topic: [Revo Terms] Context  (Read 1769 times)
doze and 2 Guests are viewing this topic.
rthrash
Foundation
*
Posts: 9,515



WWW
« on: Oct 06, 2008, 08:20 AM »

Contexts can be used to accomplish a variety of end results in Revolution, including multiple language sites, Manager access, etc. Let's talk about "contexts" here.
Logged

MODx is a framework that allows web professionals to turn over sites to end-users for daily maintenance without worrying. Community participation and questions are encouraged, especially when you help us help you, read the wiki, and review snippet parameters – even if you have to look at the source. Searching the forums helps, too.
Ryan Thrash
MODx Co-Founder
Principal @ Collabpad
work productively.
work intelligently.
work together.
koshaque
Jr. Member
*
Posts: 49


« Reply #1 on: Oct 09, 2008, 03:35 AM »

Contexts can be used to accomplish a variety of end results in Revolution, including multiple language sites, Manager access, etc. Let's talk about "contexts" here.
Great!
I would be very appriciated if someone told, HOW EXACTLY one can do multiple language sites using contexts.
Kinda step-by-step guide  Cheesy
Logged
OpenGeek
MODx Co-Founder
Moderator
*
Posts: 5,007


looking a little more like my avatar again...


WWW
« Reply #2 on: Oct 09, 2008, 10:03 AM »

There is no "HOW EXACTLY" to describe with regard to L10n in MODx Revolution.  That's up to the requirements and details of the site being developed, and the developer writing the snippets and plugins to control it.  Contexts simply provide a way to organize a set of pages, isolate cache files and plugins, and override system settings.  That's it.

So you could create a context per language or culture your site is to support, and then you can switch contexts using a plugin that detects users language preferences (how ever you want to determine that).
Logged

Jason Coward
MODx Co-Founder
xPDO Founder
Principal @ Collabpad
work productively.
work intelligently.
work together.
If you think of yourselves as helpless and ineffectual, it is certain that you will create a despotic government to be your master. The wise despot, therefore, maintains among his subjects a popular sense that they are helpless and ineffectual.
  — Frank Herbert
dev_cw
Testers
*
Posts: 2,696



WWW
« Reply #3 on: Oct 09, 2008, 11:25 AM »

I am a little fuzzy on contexts as well. I understand the principal, and have seen code examples working with them. But not sure when to use them and why.

For example in 09x we can use containers to group language files and some snippets to identity the language and go to the correct container. Would using contexts for this be any more efficient?

If there is more than one context is there a system setting to select the default context? Can documents be shared between contexts?  Why is there a context for ajax and would ajax work without a context? I can create a context but I cant create a document in a context, how do I assign a resource to a context? Should there be a Select Context option when creating a document like there is for templates? Do contexts have independent caches? Should average users be concerned about contexts?

As you can see I don't quite get it  Roll Eyes
Logged

Shane Sponagle | Snippet Call Anatomy | Document Specific Variables

Something is happening here, but you don't know what it is.
Do you, Mr. Jones?  -  [bob dylan]
OpenGeek
MODx Co-Founder
Moderator
*
Posts: 5,007


looking a little more like my avatar again...


WWW
« Reply #4 on: Oct 09, 2008, 12:18 PM »

Yeah, I am aware that folks don't understand all about it yet.  There are a number of things to cover when working with contexts, but the most important is that you limit the cache files to a single section of the site.  For beta, it will be imperative that we have some sample packages that will install a multi-lingual site demonstration, including all the snippets, plugins, and content separated into contexts.

A couple of notes though to answer your specific questions:
For example in 09x we can use containers to group language files and some snippets to identity the language and go to the correct container. Would using contexts for this be any more efficient?
Yes, because you would only load information about the specific context the document is being loaded in.  It also allows cultural specific sections of the site to be organized into separate subdomains, either by serving them all from a single virtual host and single index.php with a plugin to decide which context to load, or by having multiple virtual hosts and index.php's in each that load a specific context.  Examples of both approaches should be prepared and discussed.

If there is more than one context is there a system setting to select the default context?
The index.php initializes the 'web' context by default, so it is the default context.  You can have other index.php's (also known as gateways or front-controllers) that specifically initialize a context by name.

Can documents be shared between contexts?
In Revolution 2.0.0, no; each Resource will be confined to a single context.  2.1 will likely include features to allow Resources (formerly Documents) to exist in a primary context and any number of additional contexts.

However, you can use the new SymLink Resource type to create Resources in other contexts which forward requests to pages in another context, displaying that content as if it existed at the URL location defined by the SymLink.

Why is there a context for ajax and would ajax work without a context?
Contexts, since they allow overriding system settings, allow you to redefine almost all aspects of MODx request and response handling.  The mgr and connector contexts each define their own custom Request handler class for routing and processing requests.  Since the mgr uses Smarty, the mgr context defines a Request class (modManagerRequest) that takes of everything needed to render the Smarty templates.  Similarly, the connectors (or Ajax context) has modConnectorRequest to handle Ajax requests and responses most efficiently.  Users can define their own custom Request handlers as well, so you can create a context to render a set of Smarty templates, or integrate with another software application that would not generally work with the regular front-end (web context) Request handler.

I can create a context but I cant create a document in a context, how do I assign a resource to a context?
You should be able to use the right-click context menu in the tree to create a document in a specific context.  If that doesn't work, it's a bug.

Should there be a Select Context option when creating a document like there is for templates?
Yes, that is a good idea, though you should be able to drag and drop them between contexts as well.

Do contexts have independent caches?
Yes, all the cache files, except the system settings cache, are divided by Context.  This means all the Resources (and Plugins) defined for a specific context are loaded only when needed in a specific Context.  MODx loads Contexts on demand, for instance, if you create a Wayfinder instance and wanted to list Resources from multiple contexts, those would be loaded dynamically as needed.

Should average users be concerned about contexts?
Average users is hard to define, but in general, probably not.  It is an additional organizational feature, but generally would be involved in some kind of specific site requirement, or be used by a specific add-on or core extension package automatically.  Users interested in multi-domain, sub-domain, multi-site, and/or multi-lingual deployments will likely need to understand what it means however, as well as users with large numbers of Resources that would benefit from isolation into contexts (for caching purposes).
Logged

Jason Coward
MODx Co-Founder
xPDO Founder
Principal @ Collabpad
work productively.
work intelligently.
work together.
If you think of yourselves as helpless and ineffectual, it is certain that you will create a despotic government to be your master. The wise despot, therefore, maintains among his subjects a popular sense that they are helpless and ineffectual.
  — Frank Herbert
dev_cw
Testers
*
Posts: 2,696



WWW
« Reply #5 on: Oct 09, 2008, 01:03 PM »

Thanks for clearing all those points up, you must be getting tired of hamering these points over and over. I am getting it slowly and will benefit from the examples for sure.  Grin

I was unable to save a document (resource) when trying to create one in a new context. The create screen opens but it will not save, the button is active but it does not save (could be a local bug, i am using alpha-4).

Also when selecting the rte editor during the creation of a document in the new context (going from no editor to tiny) all the data that was filed in previously (page title etc.) gets erased and it jumps to the web context.
Logged

Shane Sponagle | Snippet Call Anatomy | Document Specific Variables

Something is happening here, but you don't know what it is.
Do you, Mr. Jones?  -  [bob dylan]
BobRay
Coding Team
*
Posts: 1,720



WWW
« Reply #6 on: Oct 09, 2008, 01:48 PM »

I'm feeling dense here because I can't figure out any easy way to create a new context in the Resource tree.  Shouldn't "Create new context" be an option on the right-click menu for the current context (and maybe on the top Site menu)?

Logged

MODx info for newbies: http://bobsguides.com/MODx.html
OpenGeek
MODx Co-Founder
Moderator
*
Posts: 5,007


looking a little more like my avatar again...


WWW
« Reply #7 on: Oct 09, 2008, 02:31 PM »

I'm feeling dense here because I can't figure out any easy way to create a new context in the Resource tree.  Shouldn't "Create new context" be an option on the right-click menu for the current context (and maybe on the top Site menu)?
It's under Tools --> Contexts.
Logged

Jason Coward
MODx Co-Founder
xPDO Founder
Principal @ Collabpad
work productively.
work intelligently.
work together.
If you think of yourselves as helpless and ineffectual, it is certain that you will create a despotic government to be your master. The wise despot, therefore, maintains among his subjects a popular sense that they are helpless and ineffectual.
  — Frank Herbert
BobRay
Coding Team
*
Posts: 1,720



WWW
« Reply #8 on: Oct 09, 2008, 03:48 PM »

I'm feeling dense here because I can't figure out any easy way to create a new context in the Resource tree.  Shouldn't "Create new context" be an option on the right-click menu for the current context (and maybe on the top Site menu)?
It's under Tools --> Contexts.

Duh!  Embarrassed

Now that I know where it is, let me ask this question. You mentioned overriding system settings above.  Suppose I want to override a system setting for snippets that run on a particular web page or two, without changing the setting for the rest of the site. Can you get me started on how to do that with contexts?



Logged

MODx info for newbies: http://bobsguides.com/MODx.html
OpenGeek
MODx Co-Founder
Moderator
*
Posts: 5,007


looking a little more like my avatar again...


WWW
« Reply #9 on: Oct 09, 2008, 04:12 PM »

Now that I know where it is, let me ask this question. You mentioned overriding system settings above.  Suppose I want to override a system setting for snippets that run on a particular web page or two, without changing the setting for the rest of the site. Can you get me started on how to do that with contexts?
Sure.

Create your context, we'll call it test.
Now create context settings with the same key as the system setting you want to override in the context.  We'll use an example for setting up some pages on a separate hostname that is pointing to the site (i.e. virtual host).  Simplest example is localhost and 127.0.0.1.  Here are my context settings for the test context configured to serve pages when the client requests something from 127.0.0.1:
keyvalue
http_host127.0.0.1
site_start3
site_urlhttp://127.0.0.1{base_url}
The site_start is different when requests come from 127.0.0.1, as is the http_host and site_url.  Notice you can refer to settings that are already available from the system settings using the setting key surrounded by braces, e.g. {base_url}.

The by simply installing this plugin and registering it for the OnHandleRequest event, your site will respond appropriately based on the HTTP_HOST sent by the client, switching contexts if necessary with the help of the $modx->switchContext() function:
Code:
<?php
switch ($modx->config['http_host']) {
    case
'127.0.0.1:80':
    case
'127.0.0.1':
        
// if the http_host is of a specific domain, switch the context
        
$modx->switchContext('test');
        break;
    default:
        
// by default, don't do anything
        
break;
}
?>
Logged

Jason Coward
MODx Co-Founder
xPDO Founder
Principal @ Collabpad
work productively.
work intelligently.
work together.
If you think of yourselves as helpless and ineffectual, it is certain that you will create a despotic government to be your master. The wise despot, therefore, maintains among his subjects a popular sense that they are helpless and ineffectual.
  — Frank Herbert
BobRay
Coding Team
*
Posts: 1,720



WWW
« Reply #10 on: Oct 09, 2008, 04:56 PM »

Is it simpler or more complicated if the pages are on the same host?  Can I switch contexts based on the document ID?

« Last Edit: Oct 13, 2008, 01:45 PM by BobRay » Logged

MODx info for newbies: http://bobsguides.com/MODx.html
OpenGeek
MODx Co-Founder
Moderator
*
Posts: 5,007


looking a little more like my avatar again...


WWW
« Reply #11 on: Oct 09, 2008, 08:04 PM »

Is is simpler or more complicated if the pages are on the same host?  Can I switch contexts based on the document ID?
You can use whatever criteria will execute in a plugin on an appropriate event (or in a snippet on a page even) to decide how/when to switch.  Same principle will apply to multi-lingual sites divided into a context per culture (i.e. language + locale, e.g. en-UK).  You can use session data or request headers and/or just about any information you can get access to and switch to the appropriate context.
Logged

Jason Coward
MODx Co-Founder
xPDO Founder
Principal @ Collabpad
work productively.
work intelligently.
work together.
If you think of yourselves as helpless and ineffectual, it is certain that you will create a despotic government to be your master. The wise despot, therefore, maintains among his subjects a popular sense that they are helpless and ineffectual.
  — Frank Herbert
The Man Can!
Testers
*
Posts: 295



WWW
« Reply #12 on: Oct 09, 2008, 11:55 PM »

Thx Jason for taking the time to explain these things. Back to the multi-lingual train of thought if we could. We're building a site with 4-6 languages and 4-6+ "countries".  I know how I'd do it in Evolution so I'll sketch that out as a point of comparison:

- Create a ton of extra TVs for alternate language pagetitles, contents, and maybe even aliases (though that's not a big deal).
- Create an extra TV or two to allow selection of "country" (or countries, as a single content element might apply to more than one country).
- Use some GeoIP location and a plugin to check visitor location, set a cookie, and serve up the appropriate language.
- Use the country TV and Ditto filtering to display the appropriate content based on location / selection.

I know I could do something like this in 2.0, but how would _you_ do it? Not asking for a step by step; just the idea.

Another potentially interesting requirement would be to restrict users to _only_ access their own language TVs (or whatever), so the Spanish translator can't edit the English translation, can't delete a document they didn't create, can't change pub_date or published status or anything other than modify their own language TVs. (I've looked at the access permissions in 2.0 but I haven't played enough to know if that'd be possible or if I'd have to modify the manager templates, which might be the best option.)

I know no two multilingual sites will have the same requirements, but would contexts help with this type of multilingual site?
Logged

Need MODx Ecommerce? Try FoxyCart!
BobRay
Coding Team
*
Posts: 1,720



WWW
« Reply #13 on: Oct 10, 2008, 12:15 AM »

Is is simpler or more complicated if the pages are on the same host?  Can I switch contexts based on the document ID?
You can use whatever criteria will execute in a plugin on an appropriate event (or in a snippet on a page even) to decide how/when to switch.  Same principle will apply to multi-lingual sites divided into a context per culture (i.e. language + locale, e.g. en-UK).  You can use session data or request headers and/or just about any information you can get access to and switch to the appropriate context.

Does it automatically switch back to the default context when the user goes back to a page in that context, or do I have to explicitly reset the context?

Logged

MODx info for newbies: http://bobsguides.com/MODx.html
OpenGeek
MODx Co-Founder
Moderator
*
Posts: 5,007


looking a little more like my avatar again...


WWW
« Reply #14 on: Oct 10, 2008, 09:37 AM »

Does it automatically switch back to the default context when the user goes back to a page in that context, or do I have to explicitly reset the context?
The gateway index.php determines the initial context, so that completely depends on the scenario.  Once you're in and a context is initialized, when and where that context changes is completely up to you.
Logged

Jason Coward
MODx Co-Founder
xPDO Founder
Principal @ Collabpad
work productively.
work intelligently.
work together.
If you think of yourselves as helpless and ineffectual, it is certain that you will create a despotic government to be your master. The wise despot, therefore, maintains among his subjects a popular sense that they are helpless and ineffectual.
  — Frank Herbert
Pages: [1] 2 3   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP

Copyright © 2005-2008 MODxCMS, All rights reserved. Contact Us
Styles by ziworks.com

Powered by SMF 1.1.4 | SMF © 2005, Simple Machines LLC

Valid XHTML 1.0! Valid CSS!