umbracoFile property empty - razor

I manage to successfully upgrade Umbraco from 4.0.3 to 4.11.10. I have 100's of xslt files in the older version and in umbracoSettings.config file I have used "UseLegacyXmlSchema" to be true. Every thing is working except when I wrote a simple razor macro below and noticed #photo.umbracoFile is always null or empty. I found this article http://allan-laustsen.blogspot.co.uk/2012/04/umbraco-razor-dynamicmedia-umbracofile.html but the solution is a bit confusing. I wonder if any one can help on this?
#using umbraco.MacroEngines
#inherits umbraco.MacroEngines.DynamicNodeContext
#{
//Check the currentpage has a value in the property 'photos'
if (Model.HasValue("sliderImages"))
{
var MediaFolder = Library.MediaById(Model.sliderImages);
<ul>
#foreach (var photo in MediaFolder.Children)
{
<li >
<img src="#photo.umbracoFile" alt="#photo.Name" />
</li>
}
</ul>
}
}

I know this is old, but since I just ran into this exact issue I thought I'd add that to republish media nodes, the only thing I've found to work is to sort and save a given parent node, republishing the whole site seems to only republish content nodes. I sort the parent media directory of the files that are experiencing this issue alphabetically and then save the new order - this allows references to .umbracoFile in razor again (i.e. the property on the affected files is no longer empty, but instead contains the path as expected).
In my case <UseLegacyXmlSchema> was already set to false and rebuilding the indexes did not work either.

Up to version 4.7 (I think), each rendering of a Media item made a call to the database. The model changed to indexing all media into the Lucene indexes much in the same way that content nodes are, and then each rendering of an image just made a call to the index. This of course made it substantially faster.
During the upgrade the media files were probably not indexed. The content will already have been indexed so this wouldn't have been an issue. So, the solution would just be to republished the entire site. This will ensure that any images referenced by the content are indexed.

Related

Extension:External Data and Categories

Situation
I retrieve data from a CSV-source using the external data-extension for mediawiki:
{{#get_web_data:url=http://example.com/names.txt|format=csv|data=name=1}}
{{#display_external_table:template=AddCat|data=1=name }}
The file names.txt simply contains names, one per row.
The template AddCat simply adds the first parameter as category: [[Category:{{{1}}}]]
Problem
The page I use this template on actually shows the name-categories on its bottom but the page itself is not visible on the category-page (I ran the jobs of course).
I assume that this has something to do with the fact that the category-name is not present in the wiki-text but is fetched from an external source.
Any suggestions how I can really add the categories?
The extension has been extensively re-factored since you posted this quesion. The current version adds the page to the categories, in your example, immediately; I've checked.
I recommend that you upgrade the extension and MediaWiki.
Have you looked in CategoryHook?
CategoryHook to which you can add auto-categorisation rules to LocalSettings.php (after including CategoryHook.php--see #Installation). Following is an example which adds articles to Category:Articles containing trees if they have any {{#tree:...}} parser functions in their content.
$wgHooks['CategoryHook'][] = 'wfCategoriseTrees';
function wfCategoriseTrees(&$parser,&$text,&$categories,$sortkey) {
$categories['Articles containing trees']
= array(preg_match('/\\{\\{#tree:/i',$text),$sortkey);
return true;
}
There are several extensions, you may want to try this one

Set Dynamic Page Title from Widget Block in Magento 2

I created a custom widget in Magento 2 and would like to dynamically change the page title in the Block's code. However, I can't seem to overwrite the page title that gets set in Magento\Cms\Block\Page::_prepareLayout().
From inside my block I have the following function. As you can see I've tried a handful of ways to make the changes to see if I can get any result.
public function _prepareLayout()
{
$this->pageConfig->getTitle()->set('TESTING');
$this->pageConfig->getTitle()->append(' - TEST');
$this->pageConfig->setMetadata('title', 'Meta Title Test');
$this->pageConfig->addBodyClass('mytestclass');
$pageMainTitle = $this->getLayout()->getBlock('page.main.title');
if ($pageMainTitle) {
$pageMainTitle->setPageTitle('Page Heading Title');
}
return parent::_prepareLayout();
}
I ran the page load through xDebug and according to the debugger my _prepareLayout does get called after the default _prepareLayout that originally sets the title. And looking through the variables in the debugger the above code all appears to be successful. However, when the page actually renders none of the above is implemented. Not even the body tag added.
I don't see much out there in regards to trying to do this from a widget block. I'm wondering if there is something I'm missing here, or if I'm approaching this the wrong way. Maybe there's a better way to achieve what I want.
Yes, I cleared, flushed, and disabled all of the cache.
Using Magento version 2.1.2
Any guidance would be greatly appreciated!

Meta tag not functioning on one page but works on all the others?

This is the meta tag:
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
It works on all pages, except 1.
The pages are being rendered with coldfusion includes <cfinclude> and is setup in a directory structure similar to MVC. The page that the tag is broken on has it's own controller (but only shows one page), but that controller is identical to the other's. I'm not sure what could be causing this.
The pages are also setup in modular design, where each function of the page is imported in chunks. Each page has it's own unique modules, so the problem is there in one of those chunks......... I just don't know what that problem could possibly be. I've been combing over the modules for the past few days and just can't find it.
What could possibly be causing this meta tag to not work? There is too much code paste here, so I'm hoping for an answer that can lead me in a direction to look for the solution. I don't believe it has anything to do with Coldfusion.
First, as drezabek stated, inspect the resulting HTML. IE is especially picky about that specific meta header. From my experience the IE=EDGE header must be the very first header on the entire page and must be the first item at the top of your <head> Check your HTML, is that the case?
Second, Coldfusion is notoriously troublesome about extra whitespace. If there is whitespace above your doctype, or possibly the header in question it could cause it to malfunction. When in doubt always use output='false' on all of your functions, even your cfscript functions. In addition, even some native CF methods add whitespace. For example serialize an ORM object, SerializeJSON(EntityLoad('blah')), and you'll see it throws in some whitespace. Joy.
The answer must lie within the HTML. View the source for a page that works, and the one that doesn't, and try looking for a difference that could cause the problem. If you can't find it, maybe post the source here?
The HTML really is the key. After you have that, finding the function that is causing the bad HTML should be easy.
It seems that I was wrong. The issue does in fact stem from Coldfusion.
Since I did not create the page that was having the issue, I overlooked an important part. The person who created it was using the cfform input tags with verification. The caused Coldfusion to insert this into the rendered page at the end of the header:
<script type="text/javascript">
<!--
_CF_checkeditUserInfo = function(_CF_this)
{
//reset on submit
_CF_error_exists = false;
_CF_error_messages = new Array();
_CF_error_fields = new Object();
_CF_FirstErrorField = null;
//display error messages and return success
if( _CF_error_exists )
{
if( _CF_error_messages.length > 0 )
{
// show alert() message
_CF_onErrorAlert(_CF_error_messages);
// set focus to first form error, if the field supports js focus().
if( _CF_this[_CF_FirstErrorField].type == "text" )
{ _CF_this[_CF_FirstErrorField].focus(); }
}
return false;
}else {
return true;
}
}
//-->
</script>
Now I'm not entirely sure what this is doing to cause the meta tag to break, but when I remove the module that causes this script to be generated, the issue is fixed. When that is removed text compare shows that the rendered headers in both pages have 0 differences.
I completely fixed my specific issue by setting the WebConfig in IIS itself.

jQuery Autocomplete working but not displaying text

I am using an Autocomplete jquery plugin in my ASP.NET site, and I cannot seem to track down what I am doing wrong on this new site. Mind you I have this 100% working in another ASP.NET site of mine, and have gone through it with a fine tooth comb comparing settings to this new project and cannot find the difference.
What is happening is that everything is wired up, the Http Handler is serializing the data to json, and writing it to the reposnse without error. The box even behaves like it is working, getting smaller as I type in more letters, but no text is displayed. I would swear this is a CSS issue, but looking at the source with the Developer toolbar, I see that the rendered list is incomplete. Here is what I see from my site that does not work:
<li jQuery16208584441255029163="12"/>
Here is what I see from my working site using the exact same plugin, CSS, references, code, etc.:
<li class="ui-menu-item" role="menuitem" jQuery16205959569234760148="7">
<a tabIndex="-1" class="ui-corner-all" jQuery16205959569234760148="33">
Text - John Smith
What am I missing here? All the code I debug is working perfectly and the results exist when being written to the HttpResponse as json. Any ideas? Thanks!
Arrrghhh. After a lot of frustration I tracked down the issue. I used a LINQ query to populate a simple DTO class with the following (3) properties:
id, label, value
...well I had modeled the class after an example I had seen, but don't typically create properties in all lower case values, so this morning I changed them to:
ID, Label, Value.
Well that innocent change was the culprit. Those properties get written to the reponse in the json and are parsed by the jQuery .js file named jquery.ui.autocomplete.js. It contains the following code (I searched down after the fact to explain this post in detail, because normally I don't care about the innerworkings of the jQuery files; I just care that they work!):
return $.map( items, function(item) {
if ( typeof item === "string" ) {
return {
label: item,
value: item
};
}
Yep the case sensitive values were not picking up my upper case names from the jSON and caused nothing to be rendered in the box.

MediaWiki: page editing allowed by creator only or with approval

I'm trying to restraint editing on the Wiki (using MediaWiki) that I'm creating as an internal project for my company.
We would like to be able to let the page creators specify none or one of the two following options:
Nobody besides the creator of this page can edit the content of this page
Anybody can edit the content of this page, but there must be an approval by the page creator before the changes are visible (whether it'd be by mail, on the wiki directly or something else - does not matter).
If the creator does not specify any of the 2 options, anybody can edit the page, and the changes are immediatly visible (default behaviour).
I've been browsing the net but I did not find an out-of-the-box solution for this. We managed to make some great custom stuff thanks to the edition of the LocalSettings file but not this.
Is there a solution for that functionality?
I don't know of an extension that would make this easy.
What I think you could do would be to take an extension like Flagged Revs or Approved Revs and make it so that instead of using groups as the determiner of approval status, it uses username. This might not be too difficult. Does this make sense?
I had the same problem as you and now i fixed it, here is the solution:
I am using http://www.mediawiki.org/wiki/Extension%3aApproved_Revs for article protection but it didn't fulfil my need it allowed the user to change the currently approved revision of the article and so the change was immediately reflected on the main page so I hacked it a bit, basically you need only one change
go to ApprovedRevs/ApprovedRevs.hooks.php
and find the following code:
static public function setLatestAsApproved( &$article , &$user, $text,
$summary, $flags, $unused1, $unused2, &$flags, $revision,
&$status, $baseRevId ) {
this is a function declaration just after it add the following code:
return false;
and it will work the way you wanted it to be i.e (the change you did will not be reflected until you approve it)