Found Somehow
Solutions I've found to my most frustrating coding and computing questions
 
 

Friday, August 14, 2009

Retrieving the translation set node ID (tnid) of the current node in Drupal

I'm mildly frustrated that Drupal 6 doesn't have a way to directly reference the current node's ID from a block.

Well, if there is a way, it's buried in documentation and just doesn't exist on the forums.

What I was specifically looking for, however, wasn't the node ID, but the Translation Set Node ID of the current node. I know it has to be available, because I can use it as an argument in the Views module.

Finding the current node's id is easy enough, if a bit silly. You can pull it from the URL, as it is the second argument arg(1). You can do this even if you have friendly URLs turned on.

$current_nid = arg(1);


Easy enough. Now $current_nid is equal to the current node's ID. If that's all you needed, you're in business.

However, what I'm looking for is the tnid, not the nid. We need to write a little query and find the tnid of the current nid. See the below code.

$current_nid = arg(1);

$sql_tnid = "SELECT N.tnid
FROM {node} N
WHERE N.nid = $current_nid";

$result_tnid = db_query($sql_tnid);

$record_tnid = db_fetch_array($result_tnid);

$tnid = $record_tnid['tnid'];


Now, feel free to use the $tnid as you like.

Labels:

Blocked in China

So, due to various incidents, a slew of social networking and related sites have been blocked in China. Easy to use proxies exist out there, but most are, in the least, a pain in the ass, and in the worst are virtually virus ambassadors.

Anyhow, blogger.com is one of the many blocked sites, so I've been absent for a bit. It's still blocked, but I'm just less lazy and feel motivated to start posting again.

There were a lot of comments on my post involving transparent backgrounds on DynamicMenuItems in asp.net. I do want to address those questions as well, so if you're still out there and commented on that post, drop me a line.

Monday, September 8, 2008

Date Format Defaults to Server's Local Language/Culture - Can be Changed

This is another little quickie, but a useful one if you're in a position that I find myself in way too often.

I'm developing an ASP.net website for an English-speaking audience, but the site is hosted in a non-English-speaking nation. In this case, China.

The server's regional settings are set to China, so, of course, it interprets dates in the local language. I'm trying to display the short-form, three-letter month names such as "Jan, Feb, Mar" and so on. The problem is, the months are showing up in Chinese. Here's what it looks like compared with what I want:


The solution is quite simple. If you want the settings to apply globally, add the following line to your Web.Config file:
<globalization culture="en-uS"></globalization>

If you'd rather set a single page, add this to the @Page directive (the line up at the top of your aspx file).
<%@ Page Culture="en-US" %>


While I'm American-English-centric, you might want to trade "en-US" for the language of your choice.

Here's a full list
of culture abbreviations. My two favorites are kok-IN (mostly because I have a juvenile sense of humor and pa-IN (because culture="pain" is some interesting social philosophy).

Saturday, August 30, 2008

Adding an item to a Databound DropDownList


There's a few reasons why you might want to add an extra item to a databound dropdownlist. For me, I just wanted to add a prompt at the top. I have a drop down list that allows the user to choose an office in a particular city. I want the first item to read "Choose an office..." or something of the sort.

In ASP.NET 2.0, one way to do this is to add an item on page load:
protected void Page_Load(object sender, EventArgs e)
{

ListItem li = new ListItem("Offices:", null);
OfficesDropDown.Items.Add(li);
}

The problem is, when the data is bound, it overwrites the item(s) you've added on page load.

The solution is quite simple. You need to add AppendDataBoundItems="true" to your DropDownList control.
<asp:DropDownList ID="OfficesDropDown" AppendDataBoundItems="true" runat="server" DataSourceID="OfficesSource" DataTextField="Office" DataValueField="Office">

</asp:DropDownList><asp:SqlDataSource ID="OfficesSource" runat="server" ConnectionString="<%$ ConnectionStrings:vd31653_dbConnectionString %>"

SelectCommand="SELECT [Office], [OfficeID] FROM [Offices]"></asp:SqlDataSource>

Note that you cannot add AppendDataBoundItems="true" to a control skin. You need to add this per control.

Thanks to SPAANJAARS.COM for this solution.

Labels: ,

Saturday, August 23, 2008

Regular Expressions

Here's a site with a great regular expressions cheat sheet.

If you're anything like me, you find it easy to remember regex syntax until you actually need it, and then suddenly it becomes esoteric knowledge.

Wednesday, August 20, 2008

Right-Floating div sinking below content

Here's another simple one, and I owe my good friend Nick for drawing my attention to it.

I have a right-floated div that should be aligned with the content on the left, but it's sinking below it, and pushing the div below it down. The div beneath is set to clear:both, but it still isn't working.


The easy solution: in your html code, place the right-floated div before the left-aligned content.

WRONG:
Here's my text<br />
With line breaks<br />
And so on. <br />
<div style="float:right; border: Solid 1px Black">
Hey, why am I down here?
</div>
<div style="clear:both; background-color:#0099FF">
I'm clearing both down here, what gives?
</div>

RIGHT:
<div style="float:right; border: Solid 1px Black">
Hey, why am I down here?
</div>
Here's my text<br />
With line breaks<br />
And so on. <br />
<div style="clear:both; background-color:#0099FF">
I'm clearing both down here, what gives?
</div>

<h1> header tags display differently in IE7 and Firefox

This is a simple one, but still rather frustrating.

If you use the <h1> tag, you'll notice that it display differently in different browsers. You might think it's just the font-size, but if you customize h1 in css, you'll find that the space above and below the text inside the <h1> tags is larger in Firefox than it is in IE7.

It's an easy, if unintuitive fix... specify the margins.

The Solution:

h1
{
font-size: large;
margin-top: 0;
margin-bottom: 1em;
}

Labels: ,