Changing Design For All Module Pages In Magento - layout

I'm doing a custom module in Magento and everything is going swimmingly... except I want to change the base layout template that all pages in the module use. I've done some googling with little success. Anyone have any answers? I want to do something along the lines of:
...
<optionbox>
<reference name="root">
<action method="setTemplate"><template>page/empty.phtml</template></action>
</reference>
</optionbox>
As you may guess, it's a lightbox... I'm a glutton for punishment I guess :)

I notice that you've got the root of your layout update as <optionbox> which in theory should cover all controllers and actions under that module. However, I've only ever seen this done with <optionbox_index> where index is from IndexController in your module. So perhaps try this replaced with your controller name:
<layout>
...
<optionbox_index>
<reference name="root">
<action method="setTemplate"><template>page/empty.phtml</template></action>
</reference>
</optionbox_index>
Also, you should try Alan Storm's LayoutViewer module, instructions on it's use here. That might help you debug it.
Cheers,
JD

In my modules I do it within the controller action like so:
public function listAction() {
$this->loadLayout();
$this->getLayout()->getBlock('root')->setTemplate('page/2columns-right.phtml');
$this->renderLayout();
}

have you tried inserting that snippet into your optionbox.xml layout file? It looks like it should work as you have it?

Related

Typescript - Further Exploration into "require" and paths

I had resigned myself to the fact that every require statement in Typescript had to be relative to the file you were typing in, but I recently discovered an application that does this differently and it confuses me. I was hoping someone with enough skill could explain how this is working to me.
The application in question is the new Raven DB HTML5 Studio, which uses typescript, you can find the whole application here:
RavenDB HTML5 Studio
When browsing its source code, I came across something interesting... if you go and look at many of the files; In specific the one I am looking at... app/viewmodels/deleteItems.ts, it has a reference at the top that reads..
import document = require("models/document");
but models/document isn't a path relative to deleteItems.ts, but this works. Can someone explain how this is happening? I'm linking you RIGHT to the exact files I'm talking about. This kind of behavior is littered all over this application.
app/viewmodels/deleteItem.ts
app/models/document.ts
This is exactly the kind of behavior I really wanted to try and emulate in my own code, since trying to keep all of the paths relative to the file I'm working in is a headache, but this program seems to be completely free of that requirement.
This doesn't necessarily involve RavenDB, but I am tagging it anyway, because perhaps someone who has read over the Raven repository will understand it and be able to answer.
Update
I am trying to mimic this behavior in my own code, and not finding any success. I am sorry if I seem outright stupid, but this is all really confusing me. Here is what my structure looks like; My repository is private, so I cannot really just link to it.
app_content
scripts
home
controls
models
editors
utils
UserControls.ts
UserMapping.ts
UserElements.ts
ui
lib
jquery
jquery.js
jquery.validate.js
jquery.ui.js
kendo
kendo.all.js
kendo.aspnetmvc.js
// other libraries
Alright, that's a general feel for my folder layout. All typescript files are under the /home folder so that I can prevent github from saving their compiled javascript and locking that.
So then, in the file UserControls.ts, it looks like this right now...
import userElements = require('./UserElements');
import userMapping = require('./UserMapping');
export class UserControls {
// code
}
No matter what combinations I have tried, this is the only format/syntax that doesn't throw errors in Visual Studio. But from what I see in the RavenDB project, I should very much be able to declare it like ...
import userElements = require('utils/UserElements');
import userMapping = require('utils/UserMapping');
export class UserControls {
// some code
}
No matter what combinations I have tried, this is the only format/syntax that doesn't throw errors in Visual Studio. But from what I see in the RavenDB project, I should very much be able to declare it like ...
That is because they are using a drandalJS configuration to tell it how to resolve the file path. (see https://github.com/ayende/ravendb/blob/New3/Raven.Studio.Html5/App/main.js)
There isn't a similar configuration (basePath) for TypeScript at the moment. Your best option is to use relative paths as you've already noticed.
PS: an old but still relevant video that shows you how requirejs config works and relevance when using TypeScript https://www.youtube.com/watch?v=4AGQpv0MKsA&hd=1
The TypeScript compiler's module resolution algorithm is essentially undocumented, unfortunately. It tries to "split the difference" between AMD and CommonJS's module resolution rules, so it's somewhat hard to reason about.
What you're seeing here is an attempt to mimic CommonJS's "walk up the tree" resolution rule. When in the path C:\a\b\c\d resolving x, first C:\a\b\c\d\x is tried, then C:\a\b\c\x, then C:\a\b\x, and so on until it hits the root folder and gives up.

Missing Windows.System error in N=5 MvvmCross sample using XS on Mac

I'm trying to compile the N=5 solution from N+1 days of MvvmCross series (https://github.com/slodge/NPlus1DaysOfMvvmCross/tree/master/N-05-MultiPage) using XS (Stable)` on a Mac. I'm getting the following error:
Error CS0234: The type or namespace name `Windows' does not exist in the namespace `System'. Are you missing an assembly reference? (CS0234) (MultiPage.Core)
This is triggered by the reference to System.Windows.Input.ICommand.
All the previous examples from the N+1 day series work without having to change assemblies. I was initially getting an additional error (missing MvxCommand) on this solution, which went away when I replaced the assemblies in References with the ones with same names but from MvvmCross-Binaries (from the XS-iOS-Mac folder). I also tried following the N=22 example (which is Mac-based) and applying it to N=5, with no avail.
It seems that anything that needs ICommand would be broken for me.
Any idea on how to fix this to compile on a Mac? Thanks.
Official support for PCLs is due any day now from Xamarin.
Until this comes along then support on the Mac requires a bit of .csproj editing in order to make the PC-nuget solutions build.
The easiest way to get these projects to build is:
to switch the assembly hint paths from the portable-win+net45+MonoAndroid16+MonoTouch40+sl40+wp71 path to the MonoTouch40 path.
and to add the System.Windows shim assembly to the list (the .Net and .Xml.Serialization shims may also be needed if your core project uses these areas)
After doing this in N=21, the references part of the Core csproj file looks like:
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Windows">
<HintPath>..\packages\MvvmCross.PortableSupport.3.0.6\lib\MonoTouch40\System.Windows.dll</HintPath>
</Reference>
<Reference Include="Cirrious.CrossCore">
<HintPath>..\packages\MvvmCross.HotTuna.CrossCore.3.0.6\lib\MonoTouch40\Cirrious.CrossCore.dll</HintPath>
</Reference>
<Reference Include="Cirrious.MvvmCross">
<HintPath>..\packages\MvvmCross.HotTuna.StarterPack.3.0.6\lib\MonoTouch40\Cirrious.MvvmCross.dll</HintPath>
</Reference>
<Reference Include="Cirrious.MvvmCross.Localization">
<HintPath>..\packages\MvvmCross.HotTuna.CrossCore.3.0.6\lib\MonoTouch40\Cirrious.MvvmCross.Localization.dll</HintPath>
</Reference>
<Reference Include="Cirrious.MvvmCross.Plugins.Json">
<HintPath>..\packages\MvvmCross.HotTuna.Plugin.Json.3.0.6\lib\MonoTouch40\Cirrious.MvvmCross.Plugins.Json.dll</HintPath>
</Reference>
<Reference Include="Cirrious.MvvmCross.Plugins.JsonLocalisation">
<HintPath>..\packages\MvvmCross.HotTuna.Plugin.JsonLocalisation.3.0.6\lib\MonoTouch40\Cirrious.MvvmCross.Plugins.JsonLocalisation.dll</HintPath>
</Reference>
<Reference Include="Cirrious.MvvmCross.Plugins.ResourceLoader">
<HintPath>..\packages\MvvmCross.HotTuna.Plugin.ResourceLoader.3.0.6\lib\MonoTouch40\Cirrious.MvvmCross.Plugins.ResourceLoader.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json">
<HintPath>..\packages\MvvmCross.HotTuna.Plugin.Json.3.0.6\lib\MonoTouch40\Newtonsoft.Json.dll</HintPath>
</Reference>
</ItemGroup>
Compare this to the original at https://github.com/slodge/NPlus1DaysOfMvvmCross/blob/master/N-21-Babel/Babel.Core/Babel.Core.csproj
If this feels too 'hacky', then the alternative currently is not to use nuget, and instead to use the binaries folders - there's a walkthrough of this in N=22 - http://slodge.blogspot.com/2013/05/n22-from-basics-on-mac-n1-days-of.html
Hopefully, by the time I've finished writing this, then Xamarin will already have shipped their PCL support so this will be out of date...

Typescript compiler errors when including node.d.ts

I recently started switching form PHP to Node.js, and since I'm a huge Typescript fan, I'm using Typescript + Node.js. I had my sample compiling just fine when I started to scale up and really build my code. But then I ran into an issues. Whenever node.d.ts is referenced (with the reference doc comment) in one of my .ts files, the Typescript compiler in Node.js complains about duplicated definitions. Two of my .ts files complain about not having the node.d.ts definitons, but my main.js file doesn't. (Files below:)
search_request.ts
/// <reference path="definitions/mustache.d.ts" />
import url = module("url");
import mu = module("mu2");
export function handler(request, response) {
//code..
}
main.ts
/// <reference path="servers/search_request.ts" />
import search_request = module("./servers/search_request");
import express = module("express");
var app = express();
app.get("/search.html", search_request.handler);
app.listen(3000);
If I add <reference path="node.d.ts" /> to the top of search_request.ts, it compiles fine. If I remove it, I get warnings about missing definitions. However, if I include it in either file, compiling main.ts will give me hundreds of warnings about duplicated identifiers.
I'm not new to Typescript, but I'm new to Node.js and new to using the tsc compiler directly rather than through VS2012. What exactly am I doing wrong? Does the compiler implicitly include node.d.ts like lib.d.ts? And if so, why do I get errors when compiling search_request.ts?
So the change by Ryan Cavanaugh did fix my issue, but in a roundabout way. My real issue was exactly as you would expect: node.d.ts was included more than once (as was express.d.ts). My file structure was something like this:
C:\Project
-node.d.ts
\public
-main.ts
\definitions
-node.d.ts
So naturally, in my main.ts file, I included definitions/node.d.ts. But somehow, node (or probably tsc) was automatically including the node.d.ts file that was one directly higher than main.ts. I don't know how, and it still confuses the hell out of me, but that was the issue.
/// <reference path="servers/search_request.ts" />
import search_request = module("./servers/search_request");
import express = module("express");
A good rule of thumb is to never mix reference tags to non-.d.ts files with top-level import or export.
This should just work if you remove the reference tag to search_request.ts.

ExcludeFromCodeCoverage Isn't Working in VS2012

I have a class in my code that I don't want showing up in code coverage numbers. I added the [ExcludeFromCodeCoverage] attribute to the class definition like this:
[ExcludeFromCodeCoverage]
public class MyClass { ... }
According to the docs (http://msdn.microsoft.com/en-us/library/system.diagnostics.codeanalysis.excludefromcodecoverageattribute.aspx) this should be all I need, but the class still shows up in code coverage analysis.
I'm using VS2012/.NET 4.5 if that matters.
Any ideas why this wouldn't work?
Here's what was going on, and here's how I fixed it.
I was using a .runsettings file to exclude certain assemblies from being included in code coverage. Seems like whenever you include a .runsettings file, you must include the following configuration:
<Attributes>
<Exclude>
<Attribute>^System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute$</Attribute>
</Exclude>
</Attributes>
It doesn't seem to matter what you have in the .runsettings file - this has to be there for [ExcludeFromCodeCoverage] to work.
FYI see this article for more information on the .runsettings file: http://msdn.microsoft.com/en-us/library/jj159530.aspx
I know the approved answer is good but I wanted to add that if you start your .runsettings file from the one suggested here (https://msdn.microsoft.com/en-us/library/jj159530.aspx) you will have a pretty good base to start with (including the proposed solution here).

got subsonic compile error

I use visual studio 2010 and tried to use subsonic and i am getting the following error.
Error 2 Compiling transformation: Metadata file 'MySql.Data' could not be found D:\TradingTools\CODE\ConsoleApplication8\subsoniccomponents\Structs.tt 1 1 backtester
As you can see from the screenshot, i do have mysql.data in my references. i dunno how to fix this. Can you help fixing this problem.
http://postimage.org/image/s1es0mr79/
SubSonic uses the DbProviderFactory pattern.
The DbProviderFactory approach allows the creation of Connections/Commands/... without knowning the concrete type.
// without factory
var con = new MySqlConnection();
var cmd = new MySqlCommand();
// with factory
var factory = DbProviderFactories.GetFactory("MySql.Data.MySqlClient");
var con = factory.CreateConnection();
var cmd = factory.CreateCommand();
which is a way more generic approach.
However, in order for this to work, you have to install MySql.Data (the msi-Package) which makes some entries in the machine.config file.
That said,
I also prefer my build environment not to rely on installed software, which makes it a lot easier to switch to a new machine without installing multiple dependencies.
But this requires a little bit work:
Modify your app.config/web.config file and place this somewhere between <configuration> and </configuration>
<system.data>
<DbProviderFactories>
<remove invariant="MySql.Data.MySqlClient"/>
<add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient"
description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.4.3.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
</DbProviderFactories>
</system.data>
I just copied and pasted the snippet from
%windir%\Microsoft.NET\Framework\<version>\Config
after installing the MSI.
If your solution has multiple projects, you have to do this for the main project (so subsonic can find your provider at runtime) and in your DAL project (so subsonic can find your provider during code generation).
If you use another MySQL Version you can change that.
The second thing you have to do is to tell the templates where to find the MySql.Data.dll (if it is not in the GAC).
You can do this by editing the MySQL.ttinclude file (look at the assembly directive)
<## include file="Settings.ttinclude" #>
<## assembly name="$(SolutionDir)\Dependencies\MySql.Data.dll" #>
<## import namespace="MySql.Data.MySqlClient" #>
<#+
With these changes my solution runs find and template generation also works find on a clean install without any MySql Components installed.

Resources