template – Attempting to display specific custom attributes in a particular table format

This may not be the best place to ask this question as it might be more of a php question but I took up building a Magento site as a hobby during covid-lockdown so I thought I’ll ask here – apologies in advance.

I have a need to display certain custom attributes of a product in a particular format. I achieved it by creating a custom tab and calling the value of each attribute. Here is how the table appears and this is the desired format:

Desired Table Output

Here is a sample of the code for the table:

           <tr>
      <th class="col label" scope="row"><u>Average Quantity</u></th>
      <td class="col data" data-th="Average Quantity"><u>per Serving</u></td>
        <td class="col data" data-th="Average Quantity"><u>per 100g</u></td>        
       <?php if($product->getData('energy_serve')): ?>
    <tr>
      <th class ="col label" scope="row">Energy</th>
      <td class="col data" data-th="Energy"><?php echo $product->getData('energy_serve') ?></td>
      <td class="col data" data-th="Energy"><?php echo $product->getData('energy_100g') ?></td>
      </tr>
      <?php endif; ?>
      <?php if($product->getData('protein_serve')): ?>
    <tr>
      <th class="col label" scope="row">Protein</th>
      <td class="col data" data-th="Protein"><?php echo $product->getData('protein_serve') ?></td>
        <td class="col data" data-th="Protein"><?php echo $product->getData('protein_100g') ?></td>
      </tr>
      <?php endif; ?>

Not that great. The label is hardcoded. And there will be more attributes, I haven’t created them all yet. So, I tried to get these specific attributes to display as they do with the default template for visible attributes using Magento_Catalog::product/view/attributes.phtml template

I couldn’t manage to get them display correctly this way. I could only manage it by turning the table the other way. So the table looks like this:

Undesirable table format

And here is the code for this table:

* @var $block MagentoCatalogBlockProductViewAttributes

$_helper = $this->helper(MagentoCatalogHelperOutput::class);
$_product = $block->getProduct();
$includeAttr = ('energy_serve',
            'protein_serve',
            'fat_total_serve',
            'fat_saturated_serve',
            'carbohydrate_serve',
            'sugar_serve',
            'sodium_serve',);   
 $includeAttrExtra = ( 'energy_100g',
            'protein_100g',
            'fat_total_100g',
            'fat_saturated_100g',
            'carbohydrate_100g',
            'sugar_100g',
            'sodium_100g');                                 
$_additionalData = ();
$_additionalDataExtra = ();
$attributes = $_product->getAttributes();
   foreach ($attributes as $attribute) {
   
    if ($attribute->getIsUserDefined() && !$attribute->getIsVisibleOnFront() && in_array($attribute->getAttributeCode(), $includeAttr)) {
        $value = $attribute->getFrontend()->getValue($_product);
        if ($attribute->getFrontendInput() == 'price' && is_string($value)) {
            $value = $this->priceCurrency->convertAndFormat($value);
        }
        if (is_string($value) && strlen($value)) {
            $_additionalData($attribute->getAttributeCode()) = (
                'label' => __($attribute->getStoreLabel()),
                'value' => $value,
                'code' => $attribute->getAttributeCode(),
            );
            
        }
    }
   
    if ($attribute->getIsUserDefined() && !$attribute->getIsVisibleOnFront() && in_array($attribute->getAttributeCode(), $includeAttrExtra)) {
        $value = $attribute->getFrontend()->getValue($_product);
        if ($attribute->getFrontendInput() == 'price' && is_string($value)) {
            $value = $this->priceCurrency->convertAndFormat($value);
        }
        if (is_string($value) && strlen($value)) {
            $_additionalDataExtra($attribute->getAttributeCode()) = (
                'label' => __($attribute->getStoreLabel()),
                'value' => $value,
                'code' => $attribute->getAttributeCode(),
            );
        }
    }
}
?>

<tr>
      <th class="col label" scope="col"><u>Average Quantity</u></th>
      <?php foreach ($_additionalData as $_data): ?>
      <th class="col label" scope="row"><?= $block->escapeHtml($_data('label')) ?></td>
      <?php endforeach; ?>
      </tr>
      <tr>
      <th class="col label" scope="col"><u>per Serving</u></th>
      <?php foreach ($_additionalData as $_data): ?>
      <td class="col data" data-th="per Serving"><?= /* @noEscape */ $_helper->productAttribute($_product, $_data('value'), $_data('code')) ?></td>
      <?php endforeach; ?>
      </tr>
      <tr> 
      <th class="col label" scope="col"><u>per 100g</u></th>
      <?php foreach ($_additionalDataExtra as $_data): ?>
      <td class="col data" data-th="per 100g"><?= /* @noEscape */ $_helper->productAttribute($_product, $_data('value'), $_data('code')) ?></td>
        <?php endforeach; ?>
        </tr>

As you can see I had to split the attributes to achieve this. I’m not sure if I need to – to get the labels and values in separate array? I tried following some other advice about counting and outputting a different result on each second attribute but I kept breaking the page no matter what I tried. I’m sure I’m not implementing this properly:

    <tr>
<?php
foreach($i=1; $count($additionalData as $i => $_data); $i++;):
if($i % 2 == 1);
    echo "<th class="col label" scope="row"><?= $block->escapeHtmlAttr($_data('label')) ?></th>";
    echo "<td class="col data" data-th="per serving"><?= /* @noEscape */ $_helper->productAttribute($_product, $_data('value'), $_data('code')) ?></td>";   
   if($i % 2 == 0) 
echo "<td class="col data" data-th="per 100g"><?= /* @noEscape */ $_helper->productAttribute($_product, $_data('value'), $_data('code')) ?></td>";
echo "</tr><tr>";?></tr>

So my question really is, what do I need to do to the custom attribute array to output the data into the desired table format? What I’m trying to do is only display the label once and I’m not sure if that approach is best. Maybe my first attempt is best since it technically works as desired? I would appreciate some guidance, please.

navigation – Best way to display page full of links?

I have a page that looks like below.

enter image description here

I shrunk it in dimensions to give a broad idea of the page. So it has categories and under them there are links. What would be some of the options in terms of designing this page? I was thinking when user clicks on any link, If the link is a pdf, I could load it on the right side and show preview like below:

enter image description here

I am not sure if it’s a good idea in terms of user experience. A lot of these links are either word or pdf files to be downloaded or viewed for the user. Some will take user to an another website.

display – Macbook Pro 16″ fried all USB-C ports after using a Samsung 43″ monitor

Without putting hands on with the proper test and diagnostic equipment, there is absolutely no way to tell.

I used the original USB-C cable from Samsung, not anything cheap, so why did this happen?

Until you test the cable, you have no idea whether or not it’s at fault. However, if you have any doubt as to the functionality and reliability of said cable, cut it in half (to prevent it from being used by others) and throw it away. Replace it with another from a known good, reputable brand.

  • This could have been a failure on your monitor’s part – it just dumped way to much power into your Mac.

  • This could have been a failure on your Mac’s part.

    • USB controller that negotiates power/charging died in some way
    • The SMC (and related circuitry) could have had a component failure

I’m mainly asking because I got the laptop fixed but I’m afraid of hooking it back up to the monitor.

If I had to guess, my money would be on the Mac failing and not your monitor. However, you can get a rather inexpensive USB-C power meter to “see” what your laptop’s drawing and what your monitor (or other power source) is delivering. These run from $20 to $40USD online.

USB-C Power Meter

It’s it “pro grade?” No. Those cost hundreds and would be way overkill for what you want. But it’s “good enough.” We’re not looking to measure microvolts or check for negotiation packets. It will tell you, however, if something is majorly wrong so you can take preventative or corrective action.

worksheet function – Go into “Display” tab, click a name off the drop down list, and view that individual’s data

I have 3 tabs. “Timestamps” “Techs/Locations” and “Display.”

My form timestamps when an employee clocks in or out. I have created two separate columns to carry over the date and time from the timestamp column (which is hidden)

The form set up my sheet to have columns B:AA as each location.

As a clock in/out is performed, it records the name under the corresponding location’s column.

I want to carry over the data of the employee of my choice has onto my DISPLAY sheet. I have tried Vlookup, but it only searches in the FIRST column. I have 26 COLUMNS. There is no way around the number of columns I have discovered.

I have tried INDEX/MATCH, Query, etc. The DISPLAY sheet has a drop down list of the employees. I wanted to do something such as:

=VLOOKUP(A4,Timestamps!B2:AE,{27,28,29,30})

Here is a link to an identical sheet with all information shortened and changed:
https://docs.google.com/spreadsheets/d/1U3ZBCI8tHObUNa7dUv6j04-syd0EkOMD8e3yyQ3SVL4/edit?gid=301227841

Again, I want to be able to go into “Display” tab, click a name off the drop down list, and view that individual’s data- which would be pulled from “timestamps.”

xsl fo – Can Apache FOP display RTL languages such as Hebrew with bullet-points and other content right aligned?

I’ve been struggling to understand how Apache FOP handles Hebrew, and potentially other rtl scripts.

When generating a document it appears to still leave the content as being left aligned including bullet points.

Image showing FOP output with bullet points and text left-aligned

I previously worked with Ibex in .Net which handled this FO file as expected.

Image showing Ibex output with bullet points and text right-aligned as expected

I had a look at some previous questions such as FOP apache – support Hebrew letters which helped find some of the Java/FOP specific changes needed and some routes I tried. The reference docs here https://xmlgraphics.apache.org/fop/2.2/complexscripts.html also had info on some tags to add which didn’t fix the issue, so I am hoping I just missed something obvious rather than this just not being possible in FOP.

Here’s a stripped back FOP I used in both processors with some Lorem Ipsum text:

<?xml version="1.0" encoding="UTF-16"?>
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
  <fo:layout-master-set>
    <fo:simple-page-master master-name="core" page-height="297mm" page-width="210mm" margin-left="5mm"
                           margin-right="5mm" margin-top="9mm" margin-bottom="10mm">
      <fo:region-body region-name="Content" margin-left="5mm" margin-right="10mm" margin-top="10mm" margin-bottom="5mm"
                      column-gap="10mm" writing-mode="rl-tb" direction="rtl"/>
    </fo:simple-page-master>
  </fo:layout-master-set>
  <fo:page-sequence master-reference="core">
    <fo:flow flow-name="Content" font-family="Arial Unicode MS">
      <fo:block>
        <fo:block>קסאם מדינות מה. מיזם חשמל מיזמי רבה בה, לעריכת ופיתוחה פוליטיקה מתן מה:</fo:block>
        <fo:block>
          <fo:list-block>
            <fo:list-item>
              <fo:list-item-label end-indent="label-end()">
                <fo:block>●</fo:block>
              </fo:list-item-label>
              <fo:list-item-body start-indent="body-start()">
                <fo:block>קסאם מדינות מה. מיזם חשמל מיזמי רבה בה, לעריכת ופיתוחה פוליטיקה מתן מה.</fo:block>
              </fo:list-item-body>
            </fo:list-item>
          </fo:list-block>
        </fo:block>
      </fo:block>
    </fo:flow>
  </fo:page-sequence>
</fo:root>

I’ve tried adding the <fo:bidi-override unicode-bidi="embed" direction="rtl"> node around the text but it seemed to make no difference in FOP, and wasn’t needed in ibex.

Adding language="hebr" script="he" to the page-sequence and flow nodes also made no difference.

The intention was to have FO files we could pass environmental variables into such as “rtl” and “rl-tb” (how this was handled with Ibex). If this can be achieved but we need two separate files for rtl and ltr that is always an option. Eventually this would be used for a variety of languages including Russian, Turkish, Korean etc so having one generic file would definitely be preferred!

terminology – Is it preferable to describe a computer’s ephemeral visual data output device as a “monitor”, “display”, “screen”, or something else?

In English language UIs, is it preferable to describe a computer’s ephemeral data visual data output device as a “monitor”, “display”, “screen”, or something else?

All three of those English words can be used as verbs and nouns, leading to a little potential confusion.

Is there a standard or commonly accepted recommendation?

display – Is it possible to use a 2011 iMac as an external monitor for 2019 Macbook Pro?

I have a mid 2011 iMac, version 10.13.6 with a thunderbolt port. My work recently gave me a 2019 Macbook Pro with a thunderbolt 3 port. Is it possible to use the iMac as an external monitor? If so, what kind of cable(s) would I need?

My work also supplied my with a Zmuipng 7 in 1 adapter but not sure if that will help with this or not.

Thanks very much!

display – How to use iMac (27-inch, Late 2013) as a second monitor for Macbook Pro (13-inch, 2020)?

I bought Thunderbolt 3 (USB-c) to Thunderbolt 2 by Apple and Thunderbolt Cable (0,5m). Cmd+F2 doesn’t work for me. I guess it’s just because Apple now prevents to use old iMacs as monitor with new Macbooks. So my question mainly is there any other non-conventional way to use my iMac as a monitor with my new Macbook?
What if I run Windows in my old iMac? Would it be easier to connect it as a monitor to new Macbook?